Skip to content

fix(wget): detect -O - in trailing args absorbed by Clap#793

Open
gghez wants to merge 2 commits intortk-ai:developfrom
gghez:fix/wget-dash-o-flag-parsing
Open

fix(wget): detect -O - in trailing args absorbed by Clap#793
gghez wants to merge 2 commits intortk-ai:developfrom
gghez:fix/wget-dash-o-flag-parsing

Conversation

@gghez
Copy link

@gghez gghez commented Mar 24, 2026

Summary

When flags like --no-check-certificate precede -O -, Clap's trailing_var_arg absorbs all remaining tokens into the args vec, leaving the output field as None. This caused RTK to route through run() instead of run_stdout(), so the bare - was passed to wget as a positional URL argument — producing:

example.com FAILED: Prepended http:// to '-'

I added two helper functions in wget_cmd.rs:

  • has_stdout_output_flag() — scans trailing args for -O - / -O- / --output-document - / --output-document=-
  • strip_output_flag() — removes those tokens so they aren't duplicated when run_stdout() adds its own -O -

The routing in main.rs now checks both the Clap-parsed output field and the trailing args before deciding which path to take.

Tested with:

  • rtk wget https://example.com -O - (already worked)
  • rtk wget https://example.com --no-check-certificate -O - (was broken, now fixed)
  • rtk wget -O - https://example.com (already worked)
  • rtk wget https://example.com (no regression, still downloads to file)

14 unit tests added covering all -O flag variants and edge cases.

Fixes #716

When flags like --no-check-certificate precede -O -, Clap's
trailing_var_arg absorbs all remaining tokens into the args vec,
leaving the output field as None. This caused RTK to route through
run() instead of run_stdout(), so the bare "-" was passed to wget
as a positional URL argument.

Scan trailing args for -O - / -O- / --output-document - patterns
and strip them before routing to run_stdout().

Fixes rtk-ai#716

Signed-off-by: gghez <gghez@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Mar 24, 2026

CLA assistant check
All committers have signed the CLA.

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier labels Mar 24, 2026
@pszymkowiak
Copy link
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a bug where -O - (stdout output flag) was misinterpreted as a URL argument when preceded by other flags like --no-check-certificate, because Clap's trailing_var_arg absorbed the tokens. Adds helper functions to detect and strip the stdout output flag from trailing args, and updates routing logic accordingly.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #716


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants