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

Feature request: Add --no-{flag_name} #40

Open
parasyte opened this issue Feb 19, 2024 · 0 comments
Open

Feature request: Add --no-{flag_name} #40

parasyte opened this issue Feb 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@parasyte
Copy link
Owner

parasyte commented Feb 19, 2024

This was requested privately. The idea is to invert the value of argument flags (fields with bool value) when it defaults to true.

E.g. This would be valid and would parse --no-recurse to args.recurse == false:

#[derive(OnlyArgs)]
struct Args {
    #[default(true)]
    recurse: bool,
}

Meanwhile, if #[default(true)] is not used on the flag, then --no-recurse would be an argument parser error; only --recurse would be allowed.

Without this feature, there is no way to turn off default flags.

Potential caveats

This feature could lead to some weird ambiguities. For instance:

#[derive(OnlyArgs)]
struct Args {
    #[default(true)]
    recurse: bool,

    no_recurse: bool,
}

This cli supports two explicit flags: --recurse and --no-recurse for both struct fields, plus one implicit flag, which is also --no-recurse (on the recurse field).

These ambiguities should probably end up as compile errors.

@parasyte parasyte added the enhancement New feature or request label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant