@cryptotaxi247 / kubo / commits / c76a52e42

cmd/ipfs2: Show short help text instead for usage errors

Matt Bell committed Nov 11, 2014 at 22:14 UTC c76a52e42226448f7d03098b487615e5b95bfd12
1 file changed +10 -4
cmd/ipfs2/main.go
+10 -4
@@ -92,11 +92,12 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
92 // handle parse error (which means the commandline input was wrong,
93 // e.g. incorrect number of args, or nonexistent subcommand)
94 if err != nil {
95 + help, _ := req.Option("help").Bool()
96 +
97 // if the -help flag wasn't specified, show the error message
98 // or if a path was returned (user specified a valid subcommand), show the error message
99 // (this means there was an option or argument error)
100 if path != nil && len(path) > 0 {
99 - help, _ := req.Option("help").Bool()
101 if !help {
102 fmt.Printf(errorFormat, err)
103 }
@@ -106,8 +107,13 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
107 root = commands.Root
108 }
109
109 - // generate the help text for the command the user was trying to call (or root)
110 - htErr := cmdsCli.LongHelp("ipfs", root, path, os.Stdout)
110 + // show the long help text if the help flag was specified, otherwise short help text
111 + helpFunc := cmdsCli.ShortHelp
112 + if help {
113 + helpFunc = cmdsCli.LongHelp
114 + }
115 +
116 + htErr := helpFunc("ipfs", root, path, os.Stdout)
117 if htErr != nil {
118 fmt.Println(htErr)
119 }
@@ -210,7 +216,7 @@ func outputResponse(res cmds.Response, root *cmds.Command) error {
216
217 // if this is a client error, we try to display help text
218 if res.Error().Code == cmds.ErrClient {
213 - err := cmdsCli.LongHelp("ipfs", root, res.Request().Path(), os.Stdout)
219 + err := cmdsCli.ShortHelp("ipfs", root, res.Request().Path(), os.Stdout)
220 if err != nil {
221 fmt.Println(err)
222 }