← Back to issue list

Provide limited choices for global arguments

View original Github issue

Metadata

Project
craft-cli
Number
#219
Type
issue
State
open
Author
lengau
Labels
—
Created
Updated
Closed
—

Current evaluation

Feature request for choices/validator on GlobalArgument is already implemented: craft_cli/dispatcher.py defines both fields, validates choices and applies the validator in _parse_options, and built-in --verbosity uses them.

Suggested action: close resolved

Reason: Both requested fields already exist on the GlobalArgument dataclass in craft_cli/dispatcher.py ('choices' and 'validator', plus a bonus 'case_sensitive'), are enforced in _parse_options() via the 'Bad {arg.name} {value!r}; valid values are {choices}.' error and 'validator = arg.validator or str', and are exercised by the built-in --verbosity argument that pre_parse_args() consumes as an EmitterMode. tests/unit/test_dispatcher.py asserts the verbosity key. Nothing remains to implement; confidence is slightly reduced only because grep_repo/git_log_search errored in this environment, so the exact resolving PR SHA could not be confirmed.

Evaluated by: mr-cal-bot

Impact: 12 Quick Win: 10 Complexity: 5 Confidence: 88 Actionability: 92

Issue body

### What needs to get done Global arguments should have a way to provide a limited set of choices or a type coercion for the application. Two examples are the built-in `--verbosity`, which has a limited set of choices, and charmcraft's `--project-dir`, which provides a validator: ```python verbosity = GlobalArgument( "verbosity", "option", None, "--verbosity", "Set the verbosity level to 'quiet', 'brief', 'verbose', 'debug' or 'trace'", choices=[mode.name.lower() for mode in EmitterMode], ) project_dir = GlobalArgument( "project_dir", "option", None, "--project_dir", "Set the base directory for the project.", validator=pydantic.DirectoryPath, ) ``` `choices` matches argparse, `validator` is chosen instead of `type` since that's already used. ### Why it needs to get done Right now an app needs to parse and provide error messages for this by itself, but `craft-cli` can often do this itself.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha
Impact: 12
Quick Win: 10
Complexity: 5
Confidence: 88
Actionability: 92
close resolved Feature request for choices/validator on GlobalArgument is already implemented: craft_cli/dispatcher.py defines both fields, validates choices and applies the validator in _parse_options, and built-in --verbosity uses them.
qwen/qwen3.6-35b-a3b
Impact: 10
Quick Win: 10
Complexity: 0
Confidence: 100
Actionability: 100
close resolved The issue requests adding 'choices' and 'validator' support to GlobalArgument. These features are already implemented in the GlobalArgument dataclass and used by the built-in --verbosity argument.
qwen/qwen3.8-27b
Impact: 50
Quick Win: 35
Staleness: 75
Complexity: 30
Confidence: 85
Support Request: 0
close not a bug Feature request to add choices and validator support to craft-cli's GlobalArgument so apps don't have to parse/validate global options themselves. Already implemented in current code (GlobalArgument has choices, validator, case_sensitive fields).
qwen/qwen3.6-35b-a3b
Staleness: 95
Complexity: 40
Confidence: 90
Support Request: 10
close stale Feature request to add choices and validator support to global arguments in craft-cli, reducing validation boilerplate. Unaddressed for over two years with zero comments or maintainer engagement.
qwen3.6-35b-a3b-mtp-q6
Staleness: 95
Complexity: 20
Confidence: 85
Support Request: 10
close stale Feature request to add choices and validator parameters to GlobalArgument for built-in option validation. Untriaged, zero comments, inactive for over two years.

Update history

No update history recorded yet.

Related work

  • Likely Fixed By: craft-cli#0 (confidence 45%)

    Commit 641d393 in craft_cli/dispatcher.py history ('removed --trace and added --verbosity as a way to set all modes') matches this feature's introduction, but the PR number could not be confirmed because git_log_search was unavailable.

Related issues

No related issues found above the similarity threshold.