Skip to content

fix: reject options that contradict each other - #162

Merged
maddie merged 1 commit into
librespeed:masterfrom
BKPepe:fix/contradictory-options
Nov 23, 2026
Merged

maddie merged 1 commit into
librespeed:masterfrom
BKPepe:fix/contradictory-options

Conversation

@BKPepe

@BKPepe BKPepe commented Nov 22, 2026

Copy link
Copy Markdown
Member

--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. 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.

--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 maddie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --json is the one contradictory pair still accepted; the code comment at speedtest/helper.go:188,258 says 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/--json combined with --json-stream is already rejected at speedtest/speedtest.go:63, and --list --share only ignores the sharing request, so neither is a defect.
  • 💡 contradictory_options_test.go:19-23 — only long names are exercised; a -4 -6 row would lock the alias behaviour in place.
  • 💡 speedtest/speedtest.go:115 — the message names the canonical flags, so -4 -6 reports 'ipv4' and 'ipv6'. Harmless; only worth changing if naming exactly what the user typed matters.

Approved – ready for merge.

@maddie
maddie merged commit 7e6a359 into librespeed:master Nov 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants