Skip to content

refactor(cli): parse arguments with clap - #211

Merged
tupe12334 merged 1 commit into
mainfrom
refactor/clap-cli
Sep 24, 2026
Merged

tupe12334 merged 1 commit into
mainfrom
refactor/clap-cli

Conversation

@tupe12334

@tupe12334 tupe12334 commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #209 (review request: "use lib for the cli"). Originally stacked on #210; now rebased onto main after #209 and #210 merged.

  • Replaces the hand-written match args.as_slice() in core/src/bin/main.rs with a clap derive parser (Cli plus the CliCommand subcommands). The old print_help is gone. Its checklist-files and global-checklists sections now live in after_help.
  • Behaviour is kept:
    • With no subcommand, steplock still handles a hook event from stdin.
    • init [--global], validate, clean [--global], and -V/--version (prints steplock X.Y.Z) work as before.
    • Usage errors still exit 1. clap's default is 2, which steplock uses for hook failures, so main maps it with try_parse and use_stderr().
  • New for free: steplock help, steplock <command> --help, and usage errors that name the bad argument.
  • MSRV: clap 4.6 needs Rust 1.85, so Cargo.lock pins clap 4.5.61. I resolved it with CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback. Every new transitive dependency needs Rust ≤ 1.74.
  • Lint ratchet: clippy::needless_pass_by_value is now deny.

Note on MSRV (pre-existing, not changed here): real Rust 1.75 can't build steplock even on main. The existing toml 1.1 dependency pulls in serde_spanned 1.1.1, whose manifest Cargo 1.75 fails to parse, and Cargo.lock is lockfile v4, which Cargo 1.75 can't read. The MSRV (1.75) CI job probably still passes because rust-toolchain.toml pins stable, which overrides the toolchain the job installs. Pinning clap to 4.5 keeps this PR from making that worse, but a separate fix is needed, either raising rust-version or pinning the older dependencies.

Test plan

  • cargo test passes (6 new parser unit tests, including Cli::command().debug_assert(), and 1 new CLI --help test)
  • cargo clippy --all-targets -- -D warnings passes
  • cargo fmt -- --check passes
  • Manual: steplock --help lists commands and the extra sections; steplock --bogus prints a usage error and exits 1; steplock -V prints steplock 0.1.0

🤖 Generated with Claude Code

@tupe12334
tupe12334 force-pushed the refactor/extract-unit-tests branch 2 times, most recently from a6b979c to 18c40e4 Compare September 24, 2026 08:19
Replace the hand-written slice matching in main.rs with a clap derive
parser (`Cli` + `CliCommand`). Behaviour is kept:

- no subcommand still reads a hook event from stdin
- `init [--global]`, `validate`, `clean [--global]`, `-V/--version`
- usage errors still exit 1 (clap's default is 2, which steplock uses for
  hook failures)

Adds `steplock help` and per-command `--help` for free. clap is resolved
to 4.5.x in Cargo.lock because 4.6 needs Rust 1.85 (MSRV is 1.75).
Also promotes clippy::needless_pass_by_value to deny.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tupe12334
tupe12334 changed the base branch from refactor/extract-unit-tests to main September 24, 2026 08:23
@tupe12334
tupe12334 marked this pull request as ready for review September 24, 2026 08:27
@tupe12334
tupe12334 merged commit e7ea39b into main Sep 24, 2026
14 checks passed
@tupe12334
tupe12334 deleted the refactor/clap-cli branch September 24, 2026 08:44
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