fix(cli): validate --target flag values instead of silent fallback#139
fix(cli): validate --target flag values instead of silent fallback#139
Conversation
Previously, invalid --target values like typos silently fell back to Generic, making configuration errors hard to detect. Now uses clap's ValueEnum derive to reject unknown values at parse time with a helpful error message showing valid options. Closes #129
Summary of ChangesHello @avifenesh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the user experience and robustness of the CLI by implementing strict validation for the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a great improvement to the CLI's robustness. By using clap::ValueEnum to validate the --target flag, you've eliminated a potential source of silent errors from typos and replaced it with clear, immediate feedback to the user. The separation of concerns between TargetArg in the CLI and TargetTool in the core library is well-handled, and the new integration tests provide excellent coverage for this new behavior. I have one minor suggestion to make one of the new tests more specific.
| let stdout = String::from_utf8_lossy(&output.stdout); | ||
| // Help should list possible values for --target | ||
| assert!( | ||
| stdout.contains("claude-code") || stdout.contains("possible values"), |
There was a problem hiding this comment.
This assertion is a bit too lenient. It would pass even if only one of the expected values was present, or if the text 'possible values' appeared somewhere unrelated. Since the PR description mentions the expected output is [possible values: generic, claude-code, cursor, codex], we can make the test more specific by checking for this exact substring. This makes the test more robust and ensures the help message is formatted as expected. For better debuggability, consider including the actual stdout content in the assertion message, so if the test fails, it's immediately clear what the output was.
| stdout.contains("claude-code") || stdout.contains("possible values"), | |
| stdout.contains("[possible values: generic, claude-code, cursor, codex]"), |
References
- For better debuggability in tests, include the content of the object that fails validation within the assertion message.
There was a problem hiding this comment.
Pull request overview
This PR tightens the CLI’s --target handling so invalid values are rejected at parse time instead of silently falling back to the generic target. It introduces a typed enum for the CLI argument, wires it into config, and adds integration tests plus changelog documentation.
Changes:
- Added a
TargetArgenum derived fromValueEnumand switched the CLI--targetflag fromStringtoTargetArgwith a default ofgeneric. - Replaced manual string-to-
TargetToolmatching with aFrom<TargetArg> for TargetToolimplementation andconfig.target = cli.target.into(). - Added CLI integration tests to cover invalid target rejection, valid target acceptance, and help output, and documented the behavior change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/agnix-cli/src/main.rs |
Introduces TargetArg as a clap ValueEnum, updates the Cli struct to use it for --target, and replaces ad-hoc string matching with a clean From<TargetArg> for TargetTool conversion in validate_command. |
crates/agnix-cli/tests/cli_integration.rs |
Adds integration tests confirming that invalid/typo/case-mismatched --target values are rejected, valid values are accepted, and --help exposes possible target values. |
CHANGELOG.md |
Notes the new --target validation behavior and its impact on error messaging and typo detection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Address Gemini Code Assist review feedback to check for exact possible values substring rather than partial match.
Summary
--targetflag now validates values using clap'sValueEnumderiveChanges
TargetArgenum withValueEnumderive for CLI argument parsingtargetfield fromStringtoTargetArgwith compile-time validationFrom<TargetArg> for TargetTooltrait implementationTest plan
cargo test- 669 tests passcargo build --release- builds successfullyagnix . --target invalidfails with "invalid value 'invalid' for '--target'"agnix . --target claude-codesucceedsagnix --helpshows "[possible values: generic, claude-code, cursor, codex]"Closes #129