Skip to content

cli: add per-command help via registry (--help/-h and help <cmd>) - #12

Merged
isink17 merged 1 commit into
masterfrom
feature/cli_help
Apr 22, 2026
Merged

cli: add per-command help via registry (--help/-h and help <cmd>)#12
isink17 merged 1 commit into
masterfrom
feature/cli_help

Conversation

@isink17

@isink17 isink17 commented Apr 22, 2026

Copy link
Copy Markdown
Owner

No description provided.

@isink17
isink17 merged commit f6f775a into master Apr 22, 2026
3 checks passed
@isink17
isink17 deleted the feature/cli_help branch April 22, 2026 13:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/cli/app.go
Comment on lines +95 to 102
func hasHelpFlag(args []string) bool {
for _, a := range args {
if isRootHelpFlag(a) {
return true
}
}
return false
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
}

Comment thread internal/cli/app.go
Comment on lines +1197 to +1198
func printCommandHelp(w io.Writer, cmd *command) {
fmt.Fprintf(w, "%s %s\n", appname.BinaryName, cmd.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant