Interpret command flag aliases in the parser

This commit is contained in:
2026-10-19 19:31:23 +00:00
parent 58b71c390f
commit 75fc45f072
8 changed files with 389 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import (
"sort"
"strings"
commandmeta "gitea.maximumdirect.net/eric/CommandKit/internal/commandmeta"
"gitea.maximumdirect.net/eric/CommandKit/internal/commandpath"
)
@@ -28,6 +29,20 @@ type flagAliasContext struct {
discovery bool
}
func (aliases resolvedFlagAliases) neutralRecords() []commandmeta.FlagAlias {
keys := make([]string, 0, len(aliases.bySpelling))
for key := range aliases.bySpelling {
keys = append(keys, key)
}
sort.Strings(keys)
records := make([]commandmeta.FlagAlias, 0, len(keys))
for _, key := range keys {
alias := aliases.bySpelling[key]
records = append(records, commandmeta.FlagAlias{Source: alias.source.token(), Target: alias.target.token()})
}
return records
}
func (spelling capturedFlagSpelling) token() string {
if spelling.short {
return "-" + spelling.name