← 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 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).

Suggested action: close not a bug

Reason: The requested feature is already implemented: craft_cli/dispatcher.py's GlobalArgument dataclass now has choices (list[str] | None), validator (Callable[[str], Any] | None), and case_sensitive fields, with __post_init__ enforcing that flags can't have choices/validators and lowercasing choices when case-insensitive. The issue's own example (verbosity with choices from EmitterMode) is exactly what the current code supports, so the request is satisfied and the issue can be closed as implemented.

Impact: 50 Quick Win: 35.0 Staleness: 75 Complexity: 30 Confidence: 85 Support Request: 0

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
qwen/qwen3.8-27b
Impact: 50
Quick Win: 35.0
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.
qwen3.6-35b-a3b-mtp-q6
Staleness: 90
Complexity: 40
Confidence: 80
Support Request: 10
needs triage Add choices and validator parameters to GlobalArgument in craft-cli to automatically handle argument validation and type coercion. Open for 887 days with no comments or labels, currently unaddressed and awaiting triage or implementation.

Update history

No update history recorded yet.

Related work

  • Likely Fixed By: craft-cli/craft-cli#340 (confidence 60%)

    Commit e05899f 'chore: prepare for starbase merge (#340)' is the most recent commit that touched 'validator' in the codebase, and the current dispatcher.py already contains the choices/validator/case_sensitive fields requested in this issue.

Related issues

No related issues found above the similarity threshold.