Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide limited choices for global arguments #219

Open
lengau opened this issue Jan 12, 2024 · 0 comments · May be fixed by #220
Open

Provide limited choices for global arguments #219

lengau opened this issue Jan 12, 2024 · 0 comments · May be fixed by #220

Comments

@lengau
Copy link
Contributor

lengau commented Jan 12, 2024

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:

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.

lengau added a commit that referenced this issue Jan 12, 2024
@lengau lengau linked a pull request Jan 12, 2024 that will close this issue
3 tasks
lengau added a commit that referenced this issue Jan 12, 2024
lengau added a commit that referenced this issue Jan 12, 2024
lengau added a commit that referenced this issue Jan 12, 2024
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 a pull request may close this issue.

1 participant