-
Notifications
You must be signed in to change notification settings - Fork 2
Add group help commands for faster agent CLI discovery (MIR-801) #676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
evanphx
merged 1 commit into
main
from
mir-801-add-a-few-group-help-commands-to-speed-up-agent-us
Mar 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "text/tabwriter" | ||
|
|
||
| "miren.dev/mflags" | ||
| ) | ||
|
|
||
| type helpOpts struct { | ||
| FormatOptions | ||
| ListCommands bool `long:"commands" description:"List all commands with their synopsis"` | ||
| Commands []string `rest:"commands"` | ||
| } | ||
|
|
||
| // commandSummary is used for JSON output of --commands. | ||
| type commandSummary struct { | ||
| Path string `json:"path"` | ||
| Usage string `json:"usage"` | ||
| } | ||
|
|
||
| // NewHelpCommand returns an Infer-based help command bound to the given dispatcher. | ||
| func NewHelpCommand(d *mflags.Dispatcher) *Cmd { | ||
| return Infer("help", "Show help for one or more commands", | ||
| func(ctx *Context, opts helpOpts) error { | ||
| if opts.ListCommands { | ||
| return runListCommands(d, opts) | ||
| } | ||
| if len(opts.Commands) > 0 { | ||
| return runMultiHelp(d, opts) | ||
| } | ||
| return mflags.ErrShowHelp | ||
| }, | ||
| WithExample(mflags.Example{ | ||
| Name: "List all commands", | ||
| Body: "miren help --commands", | ||
| }), | ||
| WithExample(mflags.Example{ | ||
| Name: "List all commands as JSON", | ||
| Body: "miren help --commands --format json", | ||
| }), | ||
| WithExample(mflags.Example{ | ||
| Name: "Show help for multiple commands", | ||
| Body: "miren help app.list version sandbox.stop", | ||
| }), | ||
| ) | ||
| } | ||
|
|
||
| func runListCommands(d *mflags.Dispatcher, opts helpOpts) error { | ||
| doc := d.HelpDoc() | ||
|
|
||
| if opts.IsJSON() { | ||
| var summaries []commandSummary | ||
| collectSummaries(doc.Commands, &summaries) | ||
| return PrintJSON(summaries) | ||
| } | ||
|
|
||
| w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0) | ||
| printSummaryRows(w, doc.Commands) | ||
| return w.Flush() | ||
| } | ||
|
|
||
| func collectSummaries(cmds []mflags.CommandDoc, out *[]commandSummary) { | ||
| for _, cmd := range cmds { | ||
| *out = append(*out, commandSummary{ | ||
| Path: cmd.Path, | ||
| Usage: cmd.Usage, | ||
| }) | ||
| collectSummaries(cmd.Subcommands, out) | ||
| } | ||
| } | ||
|
|
||
| func printSummaryRows(w *tabwriter.Writer, cmds []mflags.CommandDoc) { | ||
| for _, cmd := range cmds { | ||
| fmt.Fprintf(w, "%s\t%s\n", cmd.Path, cmd.Usage) | ||
| printSummaryRows(w, cmd.Subcommands) | ||
| } | ||
| } | ||
|
|
||
| func runMultiHelp(d *mflags.Dispatcher, opts helpOpts) error { | ||
| if opts.IsJSON() { | ||
| doc := d.HelpDoc() | ||
| index := make(map[string]*mflags.CommandDoc) | ||
| indexCommands(doc.Commands, index) | ||
|
|
||
| var results []mflags.CommandDoc | ||
| for _, name := range opts.Commands { | ||
| path := strings.ReplaceAll(name, ".", " ") | ||
| cmd, ok := index[path] | ||
| if !ok { | ||
| return fmt.Errorf("unknown command: %s", name) | ||
| } | ||
| results = append(results, *cmd) | ||
| } | ||
| return PrintJSON(results) | ||
| } | ||
|
|
||
| for i, name := range opts.Commands { | ||
| path := strings.ReplaceAll(name, ".", " ") | ||
|
|
||
| if i > 0 { | ||
| fmt.Println() | ||
| fmt.Println("---") | ||
| fmt.Println() | ||
| } | ||
|
|
||
| if err := d.ShowCommandHelp(path); err != nil { | ||
| return fmt.Errorf("unknown command: %s", name) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func indexCommands(cmds []mflags.CommandDoc, index map[string]*mflags.CommandDoc) { | ||
| for i := range cmds { | ||
| index[cmds[i].Path] = &cmds[i] | ||
| indexCommands(cmds[i].Subcommands, index) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.