diff --git a/commands/command_config.go b/commands/command_config.go index fb52c7b9..7c6a3c93 100644 --- a/commands/command_config.go +++ b/commands/command_config.go @@ -2,7 +2,6 @@ package gitmedia import ( core ".." - "fmt" ) type ConfigCommand struct { @@ -11,7 +10,7 @@ type ConfigCommand struct { func (c *ConfigCommand) Run() { config := core.Config() - fmt.Printf("Endpoint: %s\n", config.Endpoint) + core.Print("Endpoint: %s\n", config.Endpoint) } func init() { diff --git a/commands/command_queues.go b/commands/command_queues.go index b754da48..40649489 100644 --- a/commands/command_queues.go +++ b/commands/command_queues.go @@ -3,7 +3,6 @@ package gitmedia import ( ".." "../queuedir" - "fmt" ) type QueuesCommand struct { @@ -12,16 +11,15 @@ type QueuesCommand struct { func (c *QueuesCommand) Run() { err := gitmedia.WalkQueues(func(name string, queue *queuedir.Queue) error { - fmt.Println(name) + gitmedia.Print(name) return queue.Walk(func(id string, body []byte) error { - fmt.Println(" " + string(body)) + gitmedia.Print(" " + string(body)) return nil }) }) if err != nil { - fmt.Println("Error walking queues") - fmt.Println(err) + gitmedia.Panic(err, "Error walking queues") } } diff --git a/commands/command_version.go b/commands/command_version.go index 697ea8fe..20f94c63 100644 --- a/commands/command_version.go +++ b/commands/command_version.go @@ -2,7 +2,6 @@ package gitmedia import ( core ".." - "fmt" ) type VersionCommand struct { @@ -16,9 +15,9 @@ func (c *VersionCommand) Setup() { func (c *VersionCommand) Run() { if c.LovesComics { - fmt.Println("Nothing may see Gah Lak Tus and survive.") + core.Print("Nothing may see Gah Lak Tus and survive.") } else { - fmt.Printf("%s v%s\n", c.Name, core.Version) + core.Print("%s v%s\n", c.Name, core.Version) } } diff --git a/commands/commands.go b/commands/commands.go index c04231a6..da0868fb 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -98,6 +98,6 @@ func registerCommand(name string, cmdcb func(*Command) RunnableCommand) { } func missingCommand(cmd *Command, subname string) { - core.Print("%s: '%s' is not a %s command. See %s help.", + core.Error("%s: '%s' is not a %s command. See %s help.", cmd.Name, subname, cmd.Name, cmd.Name) } diff --git a/logging.go b/logging.go index 7f2a4175..3c60d5ed 100644 --- a/logging.go +++ b/logging.go @@ -14,28 +14,36 @@ import ( ) var ( - Debugging = false - ErrorBuffer = &bytes.Buffer{} - ErrorWriter = io.MultiWriter(os.Stderr, ErrorBuffer) + Debugging = false + ErrorBuffer = &bytes.Buffer{} + ErrorWriter = io.MultiWriter(os.Stderr, ErrorBuffer) + OutputWriter = io.MultiWriter(os.Stdout, ErrorBuffer) ) -// Print prints a formatted message to Stderr. It also gets printed to the +// Error prints a formatted message to Stderr. It also gets printed to the // panic log if one is created for this command. -func Print(format string, args ...interface{}) { +func Error(format string, args ...interface{}) { line := fmt.Sprintf(format, args...) fmt.Fprintln(ErrorWriter, line) } +// Print prints a formatted message to Stdout. It also gets printed to the +// panic log if one is created for this command. +func Print(format string, args ...interface{}) { + line := fmt.Sprintf(format, args...) + fmt.Fprintln(OutputWriter, line) +} + // Exit prints a formatted message and exits. func Exit(format string, args ...interface{}) { - Print(format, args...) + Error(format, args...) os.Exit(2) } // Panic prints a formatted message, and writes a stack trace for the error to // a log file before exiting. func Panic(err error, format string, args ...interface{}) { - Print(format, args...) + Error(format, args...) handlePanic(err) os.Exit(2) }