Skip to content

refactor(cli): declarative flag constraints via clap (ergonomics 1/3)#35

Merged
smorin merged 1 commit into
mainfrom
refactor/cli-arg-constraints
May 30, 2026
Merged

refactor(cli): declarative flag constraints via clap (ergonomics 1/3)#35
smorin merged 1 commit into
mainfrom
refactor/cli-arg-constraints

Conversation

@smorin

@smorin smorin commented May 30, 2026

Copy link
Copy Markdown
Owner

Option 2 of the CLI ergonomics refactor (non-breaking). Replaces the growing wall of hand-written if cli.X && cli.Y { error } validation with clap's declarative constraints.

  • operation arg-group--scan / --insert / --remove / --list-sections are now mutually exclusive by construction (clap rejects two modes).
  • requires--check--scan, --desc--insert, --no-backup--atomic, --recover-forward--recover, --to-end--line, --require-match--remove.
  • Removed ~7 manual checks from main.rs; clap enforces them now.
  • Kept context-dependent checks manual (e.g. --pair works with or without -S depending on mode; valued-default flags).

User-visible: validation error wording for these constraints now comes from clap ("the following required arguments were not provided") — 4 test assertions updated to match. Same combinations are still rejected.

Suite: 143 integration + 104 lib, clippy + fmt clean. Next: Option 1 (subcommands), then Option 3 (stdin/stdout).

CLI ergonomics, option 2 (non-breaking). Replace hand-written mutual-exclusion
and requires validation with clap's `operation` arg-group (scan/insert/remove/
list-sections now mutually exclusive) and `requires` attributes (--check needs
--scan, --desc needs --insert, --no-backup needs --atomic, --recover-forward
needs --recover, --to-end needs --line, --require-match needs --remove). Removes
~7 manual checks from main.rs; clap enforces and reports them now. Error wording
for these constraints now comes from clap.
Copilot AI review requested due to automatic review settings May 30, 2026 19:32

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.

Pull request overview

This PR refactors togl-cli argument validation by moving several cross-flag constraints from imperative checks in main.rs into clap’s declarative requires/group configuration, and updates integration tests to match clap’s standardized error wording.

Changes:

  • Updated several integration tests to assert clap-style “required arguments were not provided” messages for missing dependent flags.
  • Removed multiple manual CLI validation checks in main.rs and replaced them with comments indicating clap now enforces those constraints.
  • Added requires = ... and group = "operation" annotations in cli.rs to express dependencies and mode selection declaratively.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/togl-cli/tests/integration.rs Updates failing assertions to match clap’s new validation error text for required-argument constraints.
crates/togl-cli/src/main.rs Removes several manual flag-combination checks, relying on clap for enforcement.
crates/togl-cli/src/cli.rs Adds clap requires constraints and assigns mode flags to an operation group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 49 to 52
/// List all section IDs found in files (discovery mode, no toggling)
#[arg(long = "list-sections")]
#[arg(long = "list-sections", group = "operation")]
pub list_sections: bool,

@smorin smorin merged commit 27f2fa3 into main May 30, 2026
17 checks passed
@smorin smorin deleted the refactor/cli-arg-constraints branch May 30, 2026 21:51
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.

2 participants