From 0ccc7a479940d2d7bb5e12eab41c91105519f135 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Thu, 23 Oct 2014 06:56:03 -0700 Subject: [PATCH] Add debug output to submit command --- cmd/submit.go | 28 ++++++++++++++++++++++++++++ main.go | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/cmd/submit.go b/cmd/submit.go index 4de9d1a6b..2db16e144 100644 --- a/cmd/submit.go +++ b/cmd/submit.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "log" + "os" "path/filepath" "github.com/codegangsta/cli" @@ -22,12 +23,26 @@ func Submit(ctx *cli.Context) { log.Fatal(err) } + if ctx.GlobalBool("debug") { + log.Printf("Exercises dir: %s", c.Dir) + dir, err := os.Getwd() + if err != nil { + log.Printf("Unable to get current working directory - %s", err) + } else { + log.Printf("Current dir: %s", dir) + } + } + if !c.IsAuthenticated() { log.Fatal(msgPleaseAuthenticate) } filename := ctx.Args()[0] + if ctx.GlobalBool("debug") { + log.Printf("file name: %s", filename) + } + if isTest(filename) { log.Fatal("Please submit the solution, not the test file.") } @@ -36,16 +51,29 @@ func Submit(ctx *cli.Context) { if err != nil { log.Fatal(err) } + + if ctx.GlobalBool("debug") { + log.Printf("absolute path: %s", file) + } + file, err = filepath.EvalSymlinks(file) if err != nil { log.Fatal(err) } + if ctx.GlobalBool("debug") { + log.Printf("eval symlinks (file): %s", file) + } + dir, err := filepath.EvalSymlinks(c.Dir) if err != nil { log.Fatal(err) } + if ctx.GlobalBool("debug") { + log.Printf("eval symlinks (dir): %s", dir) + } + code, err := ioutil.ReadFile(file) if err != nil { log.Fatalf("Cannot read the contents of %s - %s\n", filename, err) diff --git a/main.go b/main.go index e24640f5d..83a26051a 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,10 @@ func main() { Name: "config, c", Usage: "path to config file", }, + cli.BoolFlag{ + Name: "debug, d", + Usage: "turn on verbose logging", + }, } app.Commands = []cli.Command{ {