Keep empty and dash operands with runnable parents

This commit is contained in:
2026-10-20 01:07:23 +00:00
parent 5c26d80228
commit e47ae799d7
3 changed files with 93 additions and 3 deletions

View File

@@ -408,7 +408,10 @@ func flagUsage(flag commandmeta.Flag) string {
func splitRoutingPrefix(argv []string) ([]string, []string) {
for index, argument := range argv {
if argument == "--" || (strings.HasPrefix(argument, "-") && argument != "-") {
// Empty strings and "-" can be operands but never command names.
// Keep them out of Find, which could skip them and select a child
// from a later operand instead of retaining the runnable parent.
if argument == "" || strings.HasPrefix(argument, "-") {
return commandpath.CloneTokens(argv[:index]), commandpath.CloneTokens(argv[index:])
}
}