Add generated help and version commands

This commit is contained in:
2026-10-07 13:37:57 +00:00
parent c3448a2ebe
commit ecd2b19783
13 changed files with 736 additions and 27 deletions

View File

@@ -10,10 +10,17 @@ func (a *App) parse(args []string, options internalcobra.ParseOptions) internalc
if a == nil {
return internalcobra.Result{Failure: &internalcobra.Failure{Message: "cannot parse commands on a nil app"}}
}
return internalcobra.Parse(a.bridgeTree(), args, options)
}
func (a *App) bridgeTree() *internalcobra.Command {
if a == nil {
return nil
}
root := &internalcobra.Command{Name: a.identity.Name}
names := make([]string, 0, len(a.commands))
for name, node := range a.commands {
if !node.reserved {
if !node.reserved || node.command.payload != nil {
names = append(names, name)
}
}
@@ -21,7 +28,7 @@ func (a *App) parse(args []string, options internalcobra.ParseOptions) internalc
for _, name := range names {
root.Children = append(root.Children, bridgeCommand(a.commands[name].command))
}
return internalcobra.Parse(root, args, options)
return root
}
func bridgeCommand(command Command) *internalcobra.Command {
@@ -33,8 +40,11 @@ func bridgeCommand(command Command) *internalcobra.Command {
if command.payload != nil {
declaration.Runnable = command.payload.hasRun()
declaration.Flags = command.payload.bridgeFlags()
declaration.Arguments = command.payload.bridgeArguments()
}
for _, child := range command.children {
children := append([]Command(nil), command.children...)
sort.Slice(children, func(i, j int) bool { return children[i].name < children[j].name })
for _, child := range children {
declaration.Children = append(declaration.Children, bridgeCommand(child))
}
return declaration