mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
Handle -h and --help differently (short text vs long text)
This commit is contained in:

committed by
Juan Batiz-Benet

parent
c76a52e422
commit
7a505b44c7
@ -92,13 +92,18 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
|
||||
// handle parse error (which means the commandline input was wrong,
|
||||
// e.g. incorrect number of args, or nonexistent subcommand)
|
||||
if err != nil {
|
||||
help, _ := req.Option("help").Bool()
|
||||
var longHelp, shortHelp bool
|
||||
|
||||
if req != nil {
|
||||
longHelp, _ = req.Option("help").Bool()
|
||||
shortHelp, _ = req.Option("h").Bool()
|
||||
}
|
||||
|
||||
// if the -help flag wasn't specified, show the error message
|
||||
// or if a path was returned (user specified a valid subcommand), show the error message
|
||||
// (this means there was an option or argument error)
|
||||
if path != nil && len(path) > 0 {
|
||||
if !help {
|
||||
if !longHelp && !shortHelp {
|
||||
fmt.Printf(errorFormat, err)
|
||||
}
|
||||
}
|
||||
@ -107,9 +112,10 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
|
||||
root = commands.Root
|
||||
}
|
||||
|
||||
// show the long help text if the help flag was specified, otherwise short help text
|
||||
// show the long help text if the -help flag was specified or we are at the root command
|
||||
// otherwise, show short help text
|
||||
helpFunc := cmdsCli.ShortHelp
|
||||
if help {
|
||||
if longHelp || len(path) == 0 {
|
||||
helpFunc = cmdsCli.LongHelp
|
||||
}
|
||||
|
||||
@ -147,14 +153,23 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
|
||||
}
|
||||
|
||||
func handleHelpOption(req cmds.Request, root *cmds.Command) (helpTextDisplayed bool, err error) {
|
||||
help, err := req.Option("help").Bool()
|
||||
longHelp, err := req.Option("help").Bool()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !help {
|
||||
shortHelp, err := req.Option("h").Bool()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !longHelp && !shortHelp {
|
||||
return false, nil
|
||||
}
|
||||
err = cmdsCli.LongHelp("ipfs", root, req.Path(), os.Stdout)
|
||||
helpFunc := cmdsCli.ShortHelp
|
||||
if longHelp || len(req.Path()) == 0 {
|
||||
helpFunc = cmdsCli.LongHelp
|
||||
}
|
||||
|
||||
err = helpFunc("ipfs", root, req.Path(), os.Stdout)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -38,15 +38,13 @@ Plumbing commands:
|
||||
|
||||
block Interact with raw blocks in the datastore
|
||||
object Interact with raw dag nodes
|
||||
|
||||
|
||||
Use "ipfs <command> --help" for more information about a command.
|
||||
`,
|
||||
|
||||
Options: []cmds.Option{
|
||||
cmds.StringOption("config", "c", "Path to the configuration file to use"),
|
||||
cmds.BoolOption("debug", "D", "Operate in debug mode"),
|
||||
cmds.BoolOption("help", "h", "Show the command help text"),
|
||||
cmds.BoolOption("help", "Show the full command help text"),
|
||||
cmds.BoolOption("h", "Show a short version of the command help text"),
|
||||
cmds.BoolOption("local", "L", "Run the command locally, instead of using the daemon"),
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user