Skip to content

fix(parse): keep implicit default after a default-only flag - #1418

Merged
jdx merged 1 commit into
jdx:mainfrom
lu-zero:default-flag-sibling-after
Sep 12, 2026
Merged

fix(parse): keep implicit default after a default-only flag#1418
jdx merged 1 commit into
jdx:mainfrom
lu-zero:default-flag-sibling-after

Conversation

@lu-zero

@lu-zero lu-zero commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Once a default-only flag has been seen, later words are the default command's args.

em query / em -p query still select the sibling. em -u query is em install -u query even when query is also a command, so a default command whose positionals are an open name set (pkg, use, search) does not get UnknownFlag -u.

Closes #1417.

Summary by CodeRabbit

  • Bug Fixes

    • Improved command-line parsing when default subcommand flags precede words matching another subcommand, alias, or the configured default command.
    • Arguments following a default-only flag are now correctly assigned to the default command.
    • Improved handling of flag values, optional and variadic values, negative values, and combined short flags.
    • Preserved expected routing for parent flags, explicit sibling commands, and help requests.
  • Documentation

    • Clarified default-command flag parsing rules and examples.
  • New Features

    • Exposed argument-parsing helpers at the crate root when the specification feature is enabled.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 86ed42ba-8e8f-440b-8b07-94703940a798

📥 Commits

Reviewing files that changed from the base of the PR and between de569d0 and d213686.

📒 Files selected for processing (1)
  • argv/src/lib.rs

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The parser now commits to the default subcommand after a default-only flag, even when later words match sibling commands. Variadic flag values stop at higher-precedence subcommands without discarding the route. Tests, fixtures, documentation, and spec exports cover the updated behavior.

Changes

Default subcommand routing

Layer / File(s) Summary
Default route lookahead
argv/src/lib.rs, lib/src/parse.rs, go/argv/parser.go
Sibling names and help cancel routing only before a default-only flag appears. Variadic value collection now stops without abandoning an established default route.
Routing behavior validation
conformance/tests/default_subcommand_flags.rs, corpus/16-default-subcommand-flags.json
Conformance cases and fixtures cover sibling names, aliases, flag values, optional values, variadic values, negative values, and mixed short bundles.
Routing contract and public API
argv/src/lib.rs, go/argv/parser.go, docs/spec/reference/index.md
Comments and reference documentation describe the updated default-command parsing rule. The crate root re-exports parse_args_from and parse_args_from_argv under the spec feature.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: jdx

Merge Risk: ⚪ Minimal · up to d2136

The updated default-command routing is covered across implementations and remains mergeable.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The routing changes, tests, corpus fixtures, and documentation are within issue #1417. However, argv/src/lib.rs also adds the public spec re-exports parse_args_from and parse_args_from_argv. T… Remove the unrelated spec re-exports, or provide a direct issue-related use for them in the implementation or automated tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main parsing change: preserving the implicit default command after a default-only flag.
Linked Issues check ✅ Passed Issue #1417 requires sibling selection before a default-only flag and default-command argument routing after that flag. lib/src/parse.rs and go/argv/parser.go now reject a sibling boundary only wh…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files.
Full details: Out of Scope Changes check

Explanation

The routing changes, tests, corpus fixtures, and documentation are within issue #1417. However, argv/src/lib.rs also adds the public spec re-exports parse_args_from and parse_args_from_argv. This API change does not implement or test default-subcommand routing, and the available evidence does not show a direct requirement for it.

  • Fix all pre-merge checks with AI

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.

@lu-zero
lu-zero marked this pull request as ready for review September 12, 2026 12:47
@greptile-apps

greptile-apps Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the previously reported corpus mismatch resolved.

Findings

  1. P1 Corpus expectations contradict new routing

Summary

  • Later words matching sibling names, aliases, or the default command’s name remain default-command arguments.
  • Parent flags and command names encountered before a default-only flag retain ordinary routing.
  • Updates conformance expectations and documentation to match the intended behavior.
  • The previously reported contradictory corpus expectations are fixed; no new actionable issues were identified.

Reviews (5) · Last reviewed commit: "fix(parse): keep implicit default after ..."

Comment on lines +56 to +61
let parsed = Em::parse_from(&["-u", "query"].map(OsStr::new)).unwrap();
let Some(Commands::Install(install)) = parsed.command else {
panic!("expected install: a default-only flag already committed the line")
};
assert!(install.update);
assert_eq!(install.package.as_deref(), Some("query"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Corpus expectations contradict new routing

The updated test accepts -u query as install with package query, but corpus/16-default-subcommand-flags.json still expects unknown_flag for that input in default-flags-sibling-wins. The default-flags-alias-wins and default-flags-explicit-prefix vectors likewise retain the old error expectations for -u q and -u install. Both corpus conformance suites compare parser results against these expectations, so the intended routing change breaks existing assertions. Update these vectors and their descriptions to assert the new default-command bindings.

Knowledge Base Used: Cross-implementation conformance

A sibling name before any default-only flag still stays on the parent
(`em query`, `em -p query`). After one, later words are the default
command's args, so `em -u pkg` is not UnknownFlag -u when `pkg` is also
a command.

The same lookahead is in argv, usage-lib, and go/argv. Binding corpus
vectors that encoded the old selector rule now expect a parse.

Closes jdx#1417.
@lu-zero
lu-zero force-pushed the default-flag-sibling-after branch from de569d0 to d213686 Compare September 12, 2026 17:08
@jdx
jdx merged commit 97e5c90 into jdx:main Sep 12, 2026
11 checks passed
@lu-zero
lu-zero deleted the default-flag-sibling-after branch September 12, 2026 18:33
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.

default_subcommand_flags: a later sibling name still cancels after a default-only flag

2 participants