Repository navigation
fix: reject options that contradict each other - #162
Conversation
--ipv4 with --ipv6 and --secure with --insecure silently used the first one, and --simple with --json, --csv or --json-stream printed its lines into the machine-readable output.
maddie
left a comment
There was a problem hiding this comment.
Reviewed at 56a169d. The check fires before any side effect (server-list fetch, file read, output), main.go:232-234 prints the message once via output.Fatalf and exits 1 with empty stdout, and every documented contradiction is covered. Alias resolution is fine: urfave/cli v2.27.7 registers every name in Names() against the same bool (flag_bool.go:146-149), so -4 -6 and --4 --6 are rejected too; only ipv4/ipv6 have aliases, and the other flags do not.
Build, vet, the full suite and -race pass, and all five new cases fail on master (before this change --ipv4 --ipv6 exits 0, --simple --json mixes both formats on stdout, and --secure --insecure attempts TLS and dies with server gave HTTP response to HTTPS client).
Three optional nits, none blocking:
- 💡
speedtest/speedtest.go:107-117—--csv --jsonis the one contradictory pair still accepted; the code comment atspeedtest/helper.go:188,258says CSV precedence is intentional for compatibility, so I am not asking for a change, but if the rule is meant to be exhaustive, add{OptionCSV, OptionJSON}and a table case.--csv/--jsoncombined with--json-streamis already rejected atspeedtest/speedtest.go:63, and--list --shareonly ignores the sharing request, so neither is a defect. - 💡
contradictory_options_test.go:19-23— only long names are exercised; a-4 -6row would lock the alias behaviour in place. - 💡
speedtest/speedtest.go:115— the message names the canonical flags, so-4 -6reports'ipv4' and 'ipv6'. Harmless; only worth changing if naming exactly what the user typed matters.
Approved – ready for merge.
--ipv4with--ipv6and--securewith--insecuresilently used the first one, and--simplewith--json,--csvor--json-streamprinted its lines into the machine-readable output. These pairs are now a usage error.A command line that passes two of them together ran until now, so this can break an existing script.