Capture immutable command declarations

This commit is contained in:
2026-10-11 01:15:13 +00:00
parent 476e98a463
commit de9bfdcc4c
16 changed files with 368 additions and 474 deletions

View File

@@ -27,7 +27,10 @@ func (a *App) buildBridgeTree() *internalcobra.Command {
root := &internalcobra.Command{Name: a.identity.Name}
names := make([]string, 0, len(a.commands))
for name, node := range a.commands {
if !node.reserved || node.command.payload != nil {
if node.command.record != nil && node.command.record.absent {
continue
}
if !node.reserved || node.command.record.payload != nil {
names = append(names, name)
}
}
@@ -39,19 +42,23 @@ func (a *App) buildBridgeTree() *internalcobra.Command {
}
func bridgeCommand(command Command) *internalcobra.Command {
record := command.record
declaration := &internalcobra.Command{
Name: command.name,
Summary: command.summary,
Description: command.description,
Name: record.name,
Summary: record.summary,
Description: record.description,
}
if command.payload != nil {
declaration.Runnable = command.payload.hasRun()
declaration.Flags = command.payload.bridgeFlags()
declaration.Arguments = command.payload.bridgeArguments()
if record.payload != nil {
declaration.Runnable = record.payload.hasRun()
declaration.Flags = record.payload.bridgeFlags()
declaration.Arguments = record.payload.bridgeArguments()
}
children := append([]Command(nil), command.children...)
sort.Slice(children, func(i, j int) bool { return children[i].name < children[j].name })
children := append([]Command(nil), record.children...)
sort.Slice(children, func(i, j int) bool { return children[i].record.name < children[j].record.name })
for _, child := range children {
if child.record == nil || child.record.absent {
continue
}
declaration.Children = append(declaration.Children, bridgeCommand(child))
}
return declaration