Refactor: Migrate to clap for CLI argument parsing#3
Merged
Conversation
- Replace complex custom argument parsing with clap derive macros - Remove custom command types and macros in favor of clap's patterns - Maintain same command interface (lint, format, list, pick) - Add auto-generated help and standard CLI flags - Simplify codebase by removing ~200 lines of custom parsing logic
- Move version from subcommand to --version/-v flag - Add detailed help with input modes and usage examples - Make subcommands required to trigger help when no args provided - Remove custom help command in favor of clap's built-in help system
…ecessary nesting.
This reverts commit 6bd3335. # Conflicts: # src/parser/engine/commands/mod.rs # src/parser/engine/help.rs
- Add comprehensive integration test suite covering all CLI commands - Fix stdin input priority over file arguments in CLI parsing - Add tempfile dev dependency for test file management - Configure IntelliJ test source folder for tests directory
- Extract shared test utilities to tests/common/mod.rs - Split monolithic cli_integration.rs into command-specific files: - version_tests.rs: version and help commands - format_tests.rs: format command with file/stdin - list_tests.rs: list command - pick_tests.rs: pick command and error cases - lint_tests.rs: lint command - Improve test naming consistency (remove "test_" prefix) - Better error assertion in pick_nonexistent_block test
a5a5c18 to
fb1278e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR replaces the custom CLI argument parsing implementation with clap, a robust and well-maintained argument parsing library. This change improves maintainability, user experience, and reduces the codebase complexity.
Key Changes
1. CLI Parsing Migration
Removed custom argument parsing logic including:
CliCmdtrait and all command-specific parsing implementationstry_parse_cmd!macro for command matchingFormatCmd,LintCmd,ListCmd,PickCmd,HelpCmd,VersionCmd)Added clap-based argument parsing:
Argsstruct with derive macros for declarative CLI definitionArgCommandsenum for subcommand handling2. Improved User Experience
--version/-vflag (in addition toversionsubcommand)3. Code Simplification
cli/args.rs)Cli::init()method with cleaner input resolution logic4. Module Restructuring
engine/commands/toengine/rootengine/commands/format.rs→engine/format.rsengine/commands/list.rs→engine/list.rsengine/commands/pick.rs→engine/pick.rsengine/commands/version.rs→engine/version.rsengine/commands/help.rs(now handled by clap)5. Code Cleanup
AccessErrors::VariableNotFoundCliErrors::UnknownCommandandCliErrors::FailedToParseArgsParsingErrors::BrokenValidatorNamingErrorsunused warningsParser,Document,Block, andLinematches!macroDependencies
clap = { version = "4.0", features = ["derive"] }to Cargo.tomlBehavioral Changes
envmn --helporenvmn help(clap standard)envmn --version/-vorenvmn version.env) behavior remains unchangedTesting
.env)Migration Notes
This is a refactoring PR with no breaking changes to the public CLI interface. All existing commands and workflows continue to work as before, but with improved error messages and help text.