Skip to content

Preserve ancestor defaults and requirements in strict subcommands - #313

Closed
FFspiky wants to merge 1 commit into
alexflint:masterfrom
FFspiky:fix/strict-subcommand-ancestor-validation
Closed

FFspiky wants to merge 1 commit into
alexflint:masterfrom
FFspiky:fix/strict-subcommand-ancestor-validation

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 17, 2026

Copy link
Copy Markdown

Strict subcommand parsing currently drops parent options from the list used to fill defaults and check required fields. For example, parsing child with StrictSubcommands: true silently leaves a parent default:"8080" port at zero, and accepts a missing parent arg:"required" option. The same definitions work correctly without strict mode.

Keep the options of every selected command for the final defaults and required-field pass. Continue using only the current command's options for strict flag lookup, so parent flags must still appear before the subcommand. This also handles nested commands and aliases without visiting unselected branches.

This is a follow-up to the strict ordering behavior introduced in #205. I did not find an existing issue or PR for the lost parent validation/defaults; the examples were reproduced against master cba3ff8 during code inspection.

Validation on macOS arm64, Go 1.27.4:

  • Six regression subcases fail on unchanged master; all 20 new subcases pass with the fix. Coverage includes parent and root requirements, nested aliases, pointer defaults, unselected commands, IgnoreDefault, environment/CLI precedence, and same-name flags at different command levels.
  • go test -race -coverprofile=profile.cov ./... -count=1: passed, 100% statement coverage.
  • go vet ./..., go build ./..., gofmt and git diff --check: passed.

Linux CI also passed the full race suite, go vet, and go build on Go 1.25.14, 1.26.11, and 1.27.4. The fork validation workflow checks out patch commit 1cd23d8 explicitly; the diagnostic workflow is kept on a separate branch.

Developed and validated with OpenAI Codex.

@FFspiky

FFspiky commented Nov 17, 2026

Copy link
Copy Markdown
Author

The upstream workflow is waiting for approval to run. Could you approve it when reviewing this PR? The fork validation passed the full race suite, vet, and build on Linux with Go 1.25, 1.26, and 1.27, checking out the exact PR source commit 1cd23d8.

@FFspiky FFspiky closed this Nov 25, 2026
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.

1 participant