Skip to content

Commit f98079e

Browse files
author
Eric Greer
authored
Merge pull request #72 from marco-m/fix-parse-error-silently-ignored
fix: fail on parse errors instead of silently ignoring them
2 parents 56e4402 + 1899495 commit f98079e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

subCommand.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,9 @@ func (sc *Subcommand) SetValueForKey(key string, value string) (bool, error) {
689689
// debugPrint("Evaluating string flag", f.ShortName, "==", key, "||", f.LongName, "==", key)
690690
if f.ShortName == key || f.LongName == key {
691691
// debugPrint("Setting string value for", key, "to", value)
692-
f.identifyAndAssignValue(value)
692+
if err := f.identifyAndAssignValue(value); err != nil {
693+
return false, err
694+
}
693695
return true, nil
694696
}
695697
}

subcommand_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,18 @@ func TestNestedSCBoolFlag(t *testing.T) {
814814
t.Fatal("Error parsing args: " + err.Error())
815815
}
816816
}
817+
818+
func TestParseErrorsAreReportedRegression(t *testing.T) {
819+
defer func() {
820+
r := recover()
821+
if r == nil {
822+
t.Fatal("Expected crash on invalid syntax")
823+
}
824+
}()
825+
826+
flaggy.ResetParser()
827+
intFlag := 42
828+
flaggy.Int(&intFlag, "i", "int", "dummy")
829+
os.Args = []string{"prog", "--int", "abc"}
830+
flaggy.Parse()
831+
}

0 commit comments

Comments
 (0)