Skip to content

Commit

Permalink
uniform debug printing
Browse files Browse the repository at this point in the history
  • Loading branch information
endorama committed Jul 16, 2018
1 parent d683ef8 commit 1c6912b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
26 changes: 8 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,15 @@ Options:

func main() {
checkAndEnableDebugMode()
if debug {
fmt.Println("Enabled debug logging...")
}
debugPrint("Enabled debug logging...")

usage := usage()
arguments, _ := docopt.ParseDoc(usage)
if debug {
fmt.Println(arguments)
}
debugPrint(fmt.Sprint(arguments))

databaseLocation, databaseFilename := getDatabaseConfigurations(arguments["--db"])

if debug {
fmt.Printf("Using database: %s/%s\n", databaseLocation, databaseFilename)
}
debugPrint(fmt.Sprintf("Using database: %s/%s", databaseLocation, databaseFilename))

os.MkdirAll(databaseLocation, 0755)
storage := NewStorage(databaseLocation, databaseFilename)
Expand Down Expand Up @@ -152,14 +146,11 @@ func add(storage Storage, name string, digits interface{}, interval interface{})
log.Fatal(err)
}

if debug {
fmt.Printf("%+v\n", key)
}
debugPrint(fmt.Sprintf("%+v", key))

marshal, _ := json.Marshal(key)
if debug {
fmt.Printf("%s\n", marshal)
}
debugPrint(fmt.Sprintf("%s", marshal))

result, err := storage.AddKey(name, []byte(marshal))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -200,9 +191,8 @@ func list(storage Storage) {
if err != nil {
fmt.Errorf("%s", err)
}
if debug {
fmt.Printf("%+v\n", key)
}
debugPrint(fmt.Sprintf("%+v", key))

if verbose {
fmt.Println(key.VerboseString())
} else {
Expand Down
6 changes: 6 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ func convertStringToInt(value string) (returnValue int) {
func base32StringToByte(data string) ([]byte, error) {
return base32.StdEncoding.DecodeString(strings.ToUpper(data))
}

func debugPrint(v string) {
if debug {
log.Println(v)
}
}

0 comments on commit 1c6912b

Please sign in to comment.