Preserve double dash values during flag alias parsing

This commit is contained in:
2026-10-20 00:28:38 +00:00
parent 744b8135f2
commit eb92f7be7f
3 changed files with 33 additions and 3 deletions

View File

@@ -92,6 +92,29 @@ func TestParseFlagAliasesPreserveValuesAndTerminators(t *testing.T) {
}
}
func TestParseConsumesDoubleDashAsAFlagValue(t *testing.T) {
for _, spelling := range []string{"--color", "--colour", "-c", "-C"} {
t.Run(spelling, func(t *testing.T) {
result := Parse(flagGrammarTree(), []string{"run", spelling, "--", "--taggy=one", "--colour=red", "--", "--taggy=operand"}, flagGrammarOptions())
if result.Failure != nil {
t.Fatalf("parse failed: %s", result.Failure.Message)
}
if !reflect.DeepEqual(result.FlagValues[0], []string{"--", "red"}) || !reflect.DeepEqual(result.FlagValues[4], []string{"one"}) {
t.Errorf("flag values = %#v", result.FlagValues)
}
if !reflect.DeepEqual(result.FlagSpellings[0], []string{spelling, "--colour"}) || !reflect.DeepEqual(result.Operands, []string{"--taggy=operand"}) {
t.Errorf("spellings = %#v, operands = %#v", result.FlagSpellings, result.Operands)
}
})
}
for _, args := range [][]string{{"run", "-v", "--", "--colour"}, {"run", "--color", "blue", "--", "--colour"}} {
result := Parse(flagGrammarTree(), args, flagGrammarOptions())
if result.Failure != nil || !reflect.DeepEqual(result.Operands, []string{"--colour"}) {
t.Errorf("Parse(%q) = %#v", args, result)
}
}
}
func TestParseHelpAliasAndUnknownShortMembers(t *testing.T) {
result := Parse(flagGrammarTree(), []string{"run", "--hlep"}, flagGrammarOptions())
if result.Failure != nil || !result.HelpRequested {