1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

cmds: fixed help stdio use

This commit is contained in:
Juan Batiz-Benet
2014-11-15 09:04:13 -08:00
parent 589851fb4e
commit 3df1513ea6

View File

@ -59,13 +59,13 @@ func main() {
// this is a local helper to print out help text. // this is a local helper to print out help text.
// there's some considerations that this makes easier. // there's some considerations that this makes easier.
printHelp := func(long bool) { printHelp := func(long bool, w io.Writer) {
helpFunc := cmdsCli.ShortHelp helpFunc := cmdsCli.ShortHelp
if long { if long {
helpFunc = cmdsCli.LongHelp helpFunc = cmdsCli.LongHelp
} }
helpFunc("ipfs", Root, invoc.path, os.Stderr) helpFunc("ipfs", Root, invoc.path, w)
} }
// parse the commandline into a command invocation // parse the commandline into a command invocation
@ -80,7 +80,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if longH || shortH { if longH || shortH {
printHelp(longH) printHelp(longH, os.Stdout)
os.Exit(0) os.Exit(0)
} }
} }
@ -89,7 +89,7 @@ func main() {
// - commands with no Run func are invoked directly. // - commands with no Run func are invoked directly.
// - the main command is invoked. // - the main command is invoked.
if invoc.cmd == nil || invoc.cmd.Run == nil { if invoc.cmd == nil || invoc.cmd.Run == nil {
printHelp(false) printHelp(false, os.Stdout)
os.Exit(0) os.Exit(0)
} }
@ -102,7 +102,7 @@ func main() {
if invoc.cmd != nil { if invoc.cmd != nil {
// we need a newline space. // we need a newline space.
fmt.Fprintf(os.Stderr, "\n") fmt.Fprintf(os.Stderr, "\n")
printHelp(false) printHelp(false, os.Stderr)
} }
os.Exit(1) os.Exit(1)
} }
@ -114,7 +114,7 @@ func main() {
// if this error was a client error, print short help too. // if this error was a client error, print short help too.
if isClientError(err) { if isClientError(err) {
printHelp(false) printHelp(false, os.Stderr)
} }
os.Exit(1) os.Exit(1)
} }