Skip to content

Answer --help and Refuse Unknown Arguments in Every Script - #542

Merged
ptr727 merged 4 commits into
developfrom
fix/539-help-and-unknown-args
Oct 26, 2026
Merged

ptr727 merged 4 commits into
developfrom
fix/539-help-and-unknown-args

Conversation

@ptr727

@ptr727 ptr727 commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Summary

Every tracked script answers --help and -h with its usage on stdout and exits 0, and refuses an argument it does not recognize, before it reads anything. This is the fleet's command-line argument rule, applied to the scripts #539 lists and to every other tracked script.

  • deploy/make-release.sh checks its arguments before it sources an environment file. --help used to be taken as the deploy root and start a release. The empty first argument OPERATIONS.md passes still selects the sourced DEPLOY_ROOT.
  • checks/check-live-urls.sh no longer takes --help as its base URL, and capture/run-wp2hugo.sh no longer ignores its arguments.
  • The checks/ gates and the capture/ scripts parse with argparse. env_docs_gate.py globs the workflows inside main rather than at import.
  • scripts/redact_media.py and capture/clean_content.py parse before they report a missing Pillow or PyYAML, so --help answers without either.

checks/tests/test_cli_usage.py discovers every tracked executable and runs each with --help, -h, and --bogus-flag. It fails on a run that calls a stubbed command (git, gh, curl, uv, and others), writes into its scratch home or working directory, or moves the tree's status. A script it does not classify fails too, so a new one is held to the rule.

Refs #539

Verification

  • The new test passes on this branch with no skip, under the system interpreter and under uvx coverage run -m unittest discover -s tests from checks/, the shape CI's lint-only leg runs. Against the base tree it fails on exactly the 15 scripts that broke the rule and passes the 6 that already used argparse.
  • checks/ and scripts/ unit suites pass, the latter with scripts/requirements.txt installed.
  • ruff check and format, and mypy, are clean on both declared directories. Pyright reports the same errors as the base.
  • shellcheck and shfmt are clean on the three shell scripts.
  • Local staging release 851dd6b, built by the changed make-release.sh with the OPERATIONS.md command, passed the build gates and the full contract, 1296 URLs.
  • A local strict review ran three rounds, and its final pass raised nothing.

Declined local-review finding

  • checks/tests/test_cli_usage.py, a design finding: the test is a smaller copy of the hub's own tests/test_cli_usage.py. That harness is hub-local, imports hub-only modules, and is not carried, so there is nothing here to extend. Consolidating means the hub carrying it, which is a hub change rather than a Blog one.

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 25, 2026 19:58
Every tracked script now answers --help and -h with its usage on stdout,
exits 0, and refuses an argument it does not recognize, before it reads
anything. make-release.sh checks its arguments before it sources an
environment file, so a flag can no longer start a release.

The checks/ gates and the capture/ scripts parse with argparse. The two
shell scripts in checks/ and deploy/, and run-wp2hugo.sh, check their
own arguments.

checks/tests/test_cli_usage.py discovers every tracked executable and
runs each with --help, -h, and an unknown flag, under stubbed commands
and empty scratch directories, and fails on any effect. A script it
does not classify fails too, so a new one is held to the rule.

Refs #539

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
redact_media.py and clean_content.py imported Pillow and PyYAML before
parsing, so neither answered --help where its module was absent, and
the checks/ leg of CI, which has neither, would have skipped both on
every run. Each now parses first and reports the missing module after,
so the CLI test runs every script with no skip.

Refs #539

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both refusals, Pillow missing and Pillow at the wrong pin, now print the
same RUN constant rather than two copies of the command.

Refs #539

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 26, 2026
Copilot AI lite review requested due to automatic review settings October 26, 2026 03:18
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: afc203b8-d8a2-432c-a3d0-43d4f5c79acb
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727

ptr727 commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 851dd6b7b5f05a24e1bce016dba1ab68d14018b6, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.50000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.98%. Comparing base (9bd721a) to head (e0c3d91).

Files with missing lines Patch % Lines
checks/env_docs_gate.py 0.00% 6 Missing ⚠️
scripts/redact_media.py 68.75% 5 Missing ⚠️
checks/media_redactions_gate.py 0.00% 4 Missing ⚠️
checks/url_parity_gate.py 33.33% 4 Missing ⚠️
checks/media_metadata_gate.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #542      +/-   ##
===========================================
- Coverage    54.07%   53.98%   -0.09%     
===========================================
  Files           12       12              
  Lines         3390     3412      +22     
===========================================
+ Hits          1833     1842       +9     
- Misses        1557     1570      +13     
Flag Coverage Δ
python-3.13 53.98% <47.50%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

checks/check-live-urls.sh mishandles --help when an extra argument is supplied; the moderate finding should be addressed before approval.

No open issues 🎉

What changed in this PR

This pull request standardizes CLI behavior across tracked scripts: --help and -h provide safe usage output, while unknown arguments are rejected before side effects. It also adds repository-wide regression coverage.

Changes:

  • Adds structured argument parsing and early validation across deployment, checks, capture, and media scripts.
  • Defers configuration access and optional-dependency errors until after argument parsing.
  • Adds executable-discovery tests for help behavior, invalid arguments, external commands, filesystem effects, and repository status.
File Summary
scripts/​redact_media.py Parses arguments before requiring Pillow.
deploy/​make-release.sh Validates arguments before reading deployment configuration.
checks/​url_parity_gate.py Adds structured positional-argument parsing.
checks/​tests/​test_github_env_gate.py Updates test calls for the argument-aware entry point.
checks/​tests/​test_cli_usage.py Adds repository-wide CLI behavior and side-effect coverage.
checks/​media_redactions_gate.py Adds early argument parsing.
checks/​media_metadata_gate.py Adds early argument parsing.
checks/​github_env_gate.py Adds parsing before GitHub access.
checks/​env_docs_gate.py Adds parsing and defers workflow discovery.
checks/​check-live-urls.sh Adds help and argument validation; help handling with extra arguments requires correction.
capture/​run-wp2hugo.sh Adds early help and unknown-argument handling.
capture/​restructure_content.py Replaces manual handling with argparse.
capture/​localize_external.py Replaces manual handling with argparse.
capture/​enumerate_media.py Parses arguments before reading capture configuration.
capture/​clean_content.py Parses before reporting a missing PyYAML dependency.
capture/​classify.py Parses arguments before reading capture configuration.
capture/​build_redirects.py Uses structured parsing for capture and export options.
capture/​build_golden.py Adds early argument parsing before configuration access.

Review effort: Lite

check-live-urls.sh counted its arguments before it looked for --help,
so `extra --help` was refused as an unexpected argument, and
run-wp2hugo.sh looked for --help only in the first position. Both now
answer help wherever it appears, as make-release.sh and every argparse
script already did, and the CLI test runs help after another argument.

Refs #539

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ptr727

ptr727 commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head e0c3d911246d8cb06d98aa16fa49860e5452e45c, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727

ptr727 commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Fixed in e0c3d91, answering the review headline on 851dd6b ("checks/check-live-urls.sh mishandles --help when an extra argument is supplied"). The script counted its arguments before it looked for --help, so extra --help was refused as an unexpected argument. It now answers help wherever it appears, before the count check. The class sweep found the same gap in capture/run-wp2hugo.sh, which looked only at the first argument, and that is fixed in the same commit. make-release.sh and every argparse script already answered help in a later position. checks/tests/test_cli_usage.py now also runs extra --help on all 22 discovered scripts and requires exit 0 with the same output as --help. The two shell scripts at 851dd6b exit 2 on that run and the current head exits 0.

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

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants