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

@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"strings"
internalcobra "gitea.maximumdirect.net/eric/CommandKit/internal/cobra"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
@@ -30,15 +29,13 @@ func (a *App) Execute(ctx context.Context, args []string, streams Streams) Outco
}
command, ok := a.commandAt(parsed.Path)
if !ok || command.payload == nil {
// Help rendering is completed in Stage 6. The dispatch boundary already
// resolves metadata requests without constructing handler input.
return Success()
return a.renderHelpOutcome(parsed.Path, streams)
}
if parsed.HelpRequested || !command.payload.hasRun() {
if _, err := command.payload.prepare(parsed.FlagValues, parsed.Operands, false); err != nil {
return a.present(Usage(err), parsed.Path, streams)
}
return Success()
return a.renderHelpOutcome(parsed.Path, streams)
}
buildInput, err := command.payload.prepare(parsed.FlagValues, parsed.Operands, true)
if err != nil {
@@ -70,7 +67,7 @@ func (a *App) commandAt(path []string) (Command, bool) {
return Command{}, true
}
command, ok := a.commands[path[0]]
if !ok || command.reserved {
if !ok || (command.reserved && command.command.payload == nil) {
return Command{}, false
}
current := command.command
@@ -133,11 +130,12 @@ func (a *App) usageLine(path []string) string {
if a != nil && a.identity.Name != "" {
name = a.identity.Name
}
parts := append([]string{name}, path...)
if len(path) == 0 {
return fmt.Sprintf("Usage: %s [command]", name)
if a != nil {
if usage, failure := internalcobra.UsageLine(a.bridgeTree(), path); failure == nil {
return "Usage: " + usage
}
}
return fmt.Sprintf("Usage: %s [flags]", strings.Join(parts, " "))
return fmt.Sprintf("Usage: %s [command]", name)
}
func hasErrorDiagnostic(diagnostics []Diagnostic) bool {