Install shell completion as an optional command
This commit is contained in:
11
registry.go
11
registry.go
@@ -6,6 +6,7 @@ import (
|
||||
"sort"
|
||||
|
||||
internalalias "gitea.maximumdirect.net/eric/CommandKit/internal/alias"
|
||||
internalcobra "gitea.maximumdirect.net/eric/CommandKit/internal/cobra"
|
||||
"gitea.maximumdirect.net/eric/CommandKit/internal/commandpath"
|
||||
)
|
||||
|
||||
@@ -122,6 +123,16 @@ func (a *App) buildInstallationCandidate(commands []Command, addedRules []Routin
|
||||
if !sameRoutingRules(rules, a.routingRules) {
|
||||
candidate.changed = true
|
||||
}
|
||||
if node := candidate.commands["completion"]; node != nil && node.command.record.completion {
|
||||
if _, exists := candidate.commands[internalcobra.CompletionQueryToken]; exists {
|
||||
return nil, fmt.Errorf("command path %q is reserved for completion", internalcobra.CompletionQueryToken)
|
||||
}
|
||||
for _, rule := range rules {
|
||||
if rule.record.kind == commandAliasRule && len(rule.record.sourcePath) > 0 && rule.record.sourcePath[0] == internalcobra.CompletionQueryToken {
|
||||
return nil, fmt.Errorf("command alias %q conflicts with completion", rule.record.sourcePath.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mappings []internalalias.Mapping
|
||||
for _, rule := range rules {
|
||||
|
||||
Reference in New Issue
Block a user