cli: add per-command help via registry (--help/-h and help <cmd>) - #12
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the CLI help system by introducing structured root and per-command help displays that include usage, flags, and examples. It also adds a dedicated help command and refactors command registration to be thread-safe and lazily initialized. Feedback suggests improving the help flag detection to respect the standard -- end-of-flags marker and updating the help output to include command aliases.
| func hasHelpFlag(args []string) bool { | ||
| for _, a := range args { | ||
| if isRootHelpFlag(a) { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
There was a problem hiding this comment.
The hasHelpFlag function should respect the standard -- end-of-flags marker. Currently, it will trigger help even if -h or --help appears after a -- argument, which is typically used to indicate that subsequent arguments should be treated as positional rather than flags.
func hasHelpFlag(args []string) bool {
for _, a := range args {
if a == "--" {
return false
}
if isRootHelpFlag(a) {
return true
}
}
return false
}| func printCommandHelp(w io.Writer, cmd *command) { | ||
| fmt.Fprintf(w, "%s %s\n", appname.BinaryName, cmd.name) |
There was a problem hiding this comment.
The command help output does not display command aliases. Since the command struct includes an aliases field, it would be helpful to show them to the user in the per-command help screen.
| func printCommandHelp(w io.Writer, cmd *command) { | |
| fmt.Fprintf(w, "%s %s\n", appname.BinaryName, cmd.name) | |
| func printCommandHelp(w io.Writer, cmd *command) { | |
| fmt.Fprintf(w, "%s %s", appname.BinaryName, cmd.name) | |
| if len(cmd.aliases) > 0 { | |
| fmt.Fprintf(w, " (%s)", strings.Join(cmd.aliases, ", ")) | |
| } | |
| fmt.Fprintln(w) |
No description provided.