Skip to content

Commit

Permalink
helptext: display options for parent commands
Browse files Browse the repository at this point in the history
This helps to understand which options are available for the given
subcommand without calling help for parent commands by providing more
informative output.

Resolves ipfs/kubo#6640
  • Loading branch information
eugene-babichenko committed Oct 15, 2019
1 parent 66cf1be commit 467c713
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/helptext.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer)
fields.Synopsis = generateSynopsis(width, cmd, pathStr)
}

// display options of parent commands
parentOptionsList := make([]string, len(path)-1)
for i := len(path) - 1; i > 0; i-- {
parentPath := path[:i]
parentCmd, err := root.Get(parentPath)
if err != nil {
return err
}
parentPathString := strings.Join(parentPath, " ")
parentOptionsString := strings.Join(optionText(width, parentCmd), "\n")
parentOptionsList = append(parentOptionsList, fmt.Sprintf("%s\n%s", parentPathString, parentOptionsString))
}
parentOptions := strings.Join(parentOptionsList, "\n\n")
fields.Options = fmt.Sprintf("%s\n\n%s", fields.Options, parentOptions)

// trim the extra newlines (see TrimNewlines doc)
fields.TrimNewlines()

Expand Down

0 comments on commit 467c713

Please sign in to comment.