rename Print() to Error(), add a Print() for STDOUT. Also remove more fmt.Print calls

This commit is contained in:
risk danger olson 2013-12-05 15:58:32 -07:00 committed by Rick Olson
parent bfe3e3346e
commit f565dd3c81
5 changed files with 22 additions and 18 deletions

@ -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() {

@ -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")
}
}

@ -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)
}
}

@ -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)
}

@ -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)
}