Skip to content

Conversation

@jqnatividad
Copy link
Collaborator

…l files

Replace 65 manually-maintained command definition files (src/cmd/*.rs), cli.rs, and mod.rs with a single usage_parser.rs module that reads static USAGE text from qsv's source files at runtime using qsv_docopt.

This eliminates all manual maintenance when commands or flags change -- just run bash generate_examples.bash to regenerate.

Key changes:

  • Add usage_parser.rs: extracts USAGE text, parses flags/subcommands/types via qsv_docopt, and builds clap::Command trees automatically
  • Add qsv_docopt dependency and clap "string" feature
  • Delete src/cli.rs, src/mod.rs, and all 65 src/cmd/*.rs files
  • Richer completions: short flags (-d, -n, etc.) now included
  • 66 commands auto-discovered (vs 65 previously)
  • Regenerate all 7 shell completion files

…l files

Replace 65 manually-maintained command definition files (src/cmd/*.rs),
cli.rs, and mod.rs with a single usage_parser.rs module that reads
`static USAGE` text from qsv's source files at runtime using qsv_docopt.

This eliminates all manual maintenance when commands or flags change --
just run `bash generate_examples.bash` to regenerate.

Key changes:
- Add usage_parser.rs: extracts USAGE text, parses flags/subcommands/types
  via qsv_docopt, and builds clap::Command trees automatically
- Add qsv_docopt dependency and clap "string" feature
- Delete src/cli.rs, src/mod.rs, and all 65 src/cmd/*.rs files
- Richer completions: short flags (-d, -n, etc.) now included
- 66 commands auto-discovered (vs 65 previously)
- Regenerate all 7 shell completion files

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Contributor

Copilot AI left a comment

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 the shell completions system from a manually-maintained approach (65 hand-written command definition files) to an automated system that parses qsv's existing static USAGE text at runtime. This significantly reduces maintenance burden and ensures completions stay in sync with the CLI automatically.

Changes:

  • Replace 68 manual files (cli.rs, mod.rs, 66 cmd/*.rs files) with a single usage_parser.rs module
  • Add qsv_docopt dependency to parse USAGE text and extract flags/subcommands
  • Auto-generate completions with enhanced short-flag support for all 7 shells
  • Update documentation to reflect the new automated workflow

Reviewed changes

Copilot reviewed 75 out of 83 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
contrib/completions/src/usage_parser.rs New core module that discovers commands, parses USAGE text, extracts flags/subcommands, and builds clap Command trees
contrib/completions/src/main.rs Updated to use usage_parser instead of manual cli.rs; adds repo root discovery
contrib/completions/src/mod.rs Removed module declarations (no longer needed)
contrib/completions/src/cli.rs Deleted - replaced by usage_parser auto-generation
contrib/completions/src/cmd/*.rs Deleted 65 manual command definition files
contrib/completions/Cargo.toml Added qsv_docopt dependency and clap "string" feature
contrib/completions/Cargo.lock Updated with new dependencies; lockfile version bumped to 4
contrib/completions/generate_examples.bash Added validation and usage instructions
contrib/completions/README.md Updated to document auto-generation workflow
contrib/completions/CLAUDE.md Completely revised to reflect new architecture
contrib/completions/examples/qsv.nu Regenerated with short flags and new subcommands (e.g., "validate schema")
Comments suppressed due to low confidence (1)

contrib/completions/generate_examples.bash:22

  • The script uses set -e which is good for error handling, but it doesn't validate that the generated completion files are non-empty or contain expected content. Consider adding basic sanity checks after generation (e.g., checking file size > 0) to catch issues early.
set -e

if [ ! -d "../../src/cmd" ]; then
    echo "Error: Cannot find ../../src/cmd/ directory." >&2
    echo "This script must be run from contrib/completions/ within the qsv repository." >&2
    exit 1
fi

# Assuming examples folder exists
cargo run -- bash > examples/qsv.bash
cargo run -- zsh > examples/qsv.zsh
cargo run -- powershell > examples/qsv.ps1
cargo run -- fish > examples/qsv.fish
cargo run -- elvish > examples/qsv.elv
cargo run -- fig > examples/qsv.fig.js
cargo run -- nushell > examples/qsv.nu

- Extract VALID_SHELLS const and validate shell arg before expensive work (fail fast)
- Replace magic number 100 with named MAX_DIR_TRAVERSAL_DEPTH constant
- Add clarifying comment on USAGE extraction first-match behavior
- Replace bare unwrap() on file_stem() with graceful match + warning
- Add dedup() after sort for subcommands to handle edge case
- Update README with explicit "66 commands" count

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 75 out of 83 changed files in this pull request and generated no new comments.

@jqnatividad jqnatividad merged commit a801112 into master Feb 11, 2026
23 checks passed
@jqnatividad jqnatividad deleted the next-gen-docopt-completions branch February 11, 2026 17:02
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