Skip to content

Commit

Permalink
Add debug output to submit command
Browse files Browse the repository at this point in the history
  • Loading branch information
kytrinyx committed Oct 23, 2014
1 parent 55fedd3 commit 0ccc7a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/codegangsta/cli"
Expand All @@ -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.")
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down

0 comments on commit 0ccc7a4

Please sign in to comment.