Skip to content

fix(cli): validate --target flag values instead of silent fallback#139

Merged
avifenesh merged 3 commits intomainfrom
feature/validate-target-values-129
Feb 3, 2026
Merged

fix(cli): validate --target flag values instead of silent fallback#139
avifenesh merged 3 commits intomainfrom
feature/validate-target-values-129

Conversation

@avifenesh
Copy link
Copy Markdown
Collaborator

Summary

  • CLI --target flag now validates values using clap's ValueEnum derive
  • Invalid values are rejected at parse time with helpful error message showing valid options
  • Prevents configuration typos from silently falling back to "generic"

Changes

  • Added TargetArg enum with ValueEnum derive for CLI argument parsing
  • Changed target field from String to TargetArg with compile-time validation
  • Added From<TargetArg> for TargetTool trait implementation
  • Removed manual string matching logic (eliminated silent fallback)
  • Added 5 new CLI integration tests for invalid target rejection

Test plan

  • cargo test - 669 tests pass
  • cargo build --release - builds successfully
  • Manual testing:
    • agnix . --target invalid fails with "invalid value 'invalid' for '--target'"
    • agnix . --target claude-code succeeds
    • agnix --help shows "[possible values: generic, claude-code, cursor, codex]"

Closes #129

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
Copilot AI review requested due to automatic review settings February 3, 2026 16:45
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 --target flag. Instead of silently defaulting to a generic option when an invalid target is provided, the CLI now explicitly rejects malformed inputs and guides the user with clear error messages. This change prevents configuration errors from going unnoticed and ensures that the application behaves predictably based on user input.

Highlights

  • Enhanced CLI Argument Validation: The --target flag in the CLI now uses clap's ValueEnum derive for robust validation, ensuring that only predefined values are accepted.
  • Improved Error Handling: Invalid --target values are now explicitly rejected at parse time, providing users with helpful error messages that list valid options, preventing silent fallbacks to 'generic'.
  • Code Refactoring for Target Selection: A new TargetArg enum has been introduced for CLI parsing, alongside a From<TargetArg> for TargetTool trait implementation, which replaces the previous manual string matching logic for target selection.
  • Comprehensive Integration Tests: Five new CLI integration tests have been added to cover various scenarios of target argument validation, including rejection of invalid, typo-ridden, and case-sensitive inputs, and verification of valid inputs and help output.
Changelog
  • CHANGELOG.md
    • Added an entry under 'Fixed' to document that the CLI --target flag now validates values instead of silently falling back to 'generic', rejecting invalid values with helpful error messages and preventing configuration typos.
  • crates/agnix-cli/src/main.rs
    • Introduced a new TargetArg enum, derived Debug, Clone, Copy, Default, and ValueEnum for clap integration, to represent CLI target arguments with kebab-case names.
    • Implemented From<TargetArg> for TargetTool to facilitate conversion from the CLI argument enum to the internal TargetTool enum.
    • Modified the Cli struct's target field from String to TargetArg, leveraging clap's value_enum attribute for automatic validation and default_value_t for default value handling.
    • Replaced the manual match statement for assigning config.target with a direct cli.target.into(), utilizing the new From trait implementation.
  • crates/agnix-cli/tests/cli_integration.rs
    • Added test_invalid_target_rejected to ensure that arbitrary invalid --target values are rejected.
    • Added test_typo_target_rejected to verify that target names with typos (e.g., claude_code instead of claude-code) are rejected.
    • Added test_case_sensitive_target_rejected to confirm that case-sensitive inputs (e.g., ClaudeCode) are rejected.
    • Added test_valid_targets_accepted to iterate and confirm that all expected valid --target values are accepted.
    • Added test_help_shows_target_possible_values to assert that the --help output correctly lists the possible values for the --target flag.
Activity
  • All 669 cargo test cases passed successfully.
  • cargo build --release completed without issues.
  • Manual testing confirmed that agnix . --target invalid fails with an appropriate error message, agnix . --target claude-code succeeds, and agnix --help correctly displays possible values for the --target flag.
  • This pull request addresses and closes issue Validate --target values (avoid silent fallback) #129.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
stdout.contains("claude-code") || stdout.contains("possible values"),
stdout.contains("[possible values: generic, claude-code, cursor, codex]"),
References
  1. For better debuggability in tests, include the content of the object that fails validation within the assertion message.

Copy link
Copy Markdown
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 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 TargetArg enum derived from ValueEnum and switched the CLI --target flag from String to TargetArg with a default of generic.
  • Replaced manual string-to-TargetTool matching with a From<TargetArg> for TargetTool implementation and config.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.

@claude
Copy link
Copy Markdown

claude Bot commented Feb 3, 2026

Code review

No 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.
@avifenesh avifenesh merged commit 3c03d87 into main Feb 3, 2026
12 checks passed
@avifenesh avifenesh deleted the feature/validate-target-values-129 branch February 3, 2026 16:54
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.

Validate --target values (avoid silent fallback)

2 participants