Skip to content

Reject shadowed global flags on proper subcommands#2255

Draft
afrancke wants to merge 1 commit into
getsops:mainfrom
afrancke:afrancke/reject-shadowed-global-subcommand-flags
Draft

Reject shadowed global flags on proper subcommands#2255
afrancke wants to merge 1 commit into
getsops:mainfrom
afrancke:afrancke/reject-shadowed-global-subcommand-flags

Conversation

@afrancke

Copy link
Copy Markdown

Fixes #2254.

Summary

Reject a flag parsed globally when a proper subcommand declares the same flag and no command-local value was supplied. This prevents a command from succeeding with a default value while silently ignoring the user's earlier global value.

The guard applies to all six commands migrated by #1333/#1391: decrypt, encrypt, rotate, edit, set, and unset. It leaves true global-only flags alone and allows the unambiguous command-local form.

Tests

  • go test ./cmd/sops
  • cargo fmt --check in functional-tests
  • cargo test proper_subcommands_reject_shadowed_global_flags
  • cargo test decrypt_output_type_after_subcommand_emits_json

The new black-box coverage verifies every observed decrypt collision (--output-type, --input-type, --output, --extract, and --ignore-mac), all six migrated proper subcommands, zero stdout on rejection, and valid JSON from the command-local placement.

Signed-off-by: Andy Francke <andy@francke.com>
@afrancke afrancke force-pushed the afrancke/reject-shadowed-global-subcommand-flags branch from 55b6d40 to 491c07f Compare July 14, 2026 06:40
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.

Proper subcommands silently shadow colliding global options before the subcommand

1 participant