Keep command routing independent of operand counts

This commit is contained in:
2026-10-20 00:22:25 +00:00
parent ccf8acd861
commit 7dad20680e
5 changed files with 110 additions and 18 deletions

View File

@@ -298,7 +298,7 @@ func validateCommandAliases(rules []RoutingRule, resolver *internalalias.Resolve
if sourceTrace.exact != nil {
return fmt.Errorf("command alias source %q conflicts with canonical command %q", record.sourcePath.String(), sourceTrace.exact.path.String())
}
if sourceTrace.operandOwner != nil {
if sourceTrace.operandOwner != nil && acceptsOperandPrefix(sourceTrace.operandOwner.command, len(record.sourcePath)-len(sourceTrace.operandOwner.path)) {
return fmt.Errorf("command alias source %q intercepts operands of canonical command %q", record.sourcePath.String(), sourceTrace.operandOwner.path.String())
}
@@ -318,15 +318,14 @@ func validateCommandAliases(rules []RoutingRule, resolver *internalalias.Resolve
func traceCanonicalPath(roots map[string]*canonicalNode, path commandpath.Path) commandAliasTrace {
var current *canonicalNode
children := roots
for index, component := range path {
for _, component := range path {
next := children[component]
if next != nil {
current = next
children = current.children
continue
}
operandCount := len(path) - index
if current != nil && acceptsOperandPrefix(current.command, operandCount) {
if current != nil && current.command.record.payload != nil && current.command.record.payload.hasRun() {
return commandAliasTrace{operandOwner: current}
}
return commandAliasTrace{}