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

Add support for arg stability attributes (unstable/deprecated) #3321

Open
2 tasks done
yaahc opened this issue Jan 20, 2022 · 2 comments
Open
2 tasks done

Add support for arg stability attributes (unstable/deprecated) #3321

yaahc opened this issue Jan 20, 2022 · 2 comments
Labels
A-builder Area: Builder API A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state.

Comments

@yaahc
Copy link

yaahc commented Jan 20, 2022

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Clap Version

3.0.10

Describe your use case

I had this idea while I was reviewing @sunshowers's CLI recommendations on versioning: https://rust-cli-recommendations.sunshowers.io/versioning.html. In their book they recommend having a stability flag or environment variable for gating new experimental features being exposed in your CLI. This made me think it would be nice if clap provided some support out of the box for managing the stability of various subsets of an App's CLI.

Describe the solution you'd like

I'm imagining two new methods being added to Arg

impl Arg {
    /// Specifies that an argument is unstable.
    ///
    /// **Note**: Unstable arguments cannot be used except when the `--unstable-options` flag is also enabled
    fn unstable(self, yes: bool) -> Self;

    /// Specifies that an argument is deprecated.
    ///
    /// **Note**: Using a deprecated argument will produce a warning unless the `--allow-deprecated` flag is also enabled
    fn deprecated(self, yes: bool) -> Self;
}

I'd expect these flags to also affect the generated help text to somehow deprioritize unstable/deprecated arguments in the generated output and to make it clear that they are not intended for general use.

Alternatives, if applicable

@epage and @sunshowers have both also suggested adding general support for custom settings / attributes so that a feature like this could be experimented with out of tree rather than needing to bake it into clap directly.

Additional Context

No response

@yaahc yaahc added the C-enhancement Category: Raise on the bar on expectations label Jan 20, 2022
@epage
Copy link
Member

epage commented Jan 20, 2022

This entails a lot of policy (flag names, whether they should be global or not, user messages, etc). This would both lock us in to specific behavior but also leave a lot of room for it not quite meeting people needs and wanting customization of it.

My proposal is we start an example that covers these cases. We then use this to explore how we could improve clap.

For example, "require an argument to be present with a value" would go a long way towards a general solution to unstable(yes) but we don't have this. We instead have "when value is set, require another argument" (as both requires_if and required_if_eq, depending on which side you want to express this relationship).

My hope is we can move clap from a closed-form API to an open-form API where we don't
need to bake all of the validation options directly into clap but allow users to create their own (#3008). This means we can add this new form of requires in a way that the compiler can trivially remove if unused, unlike the current validation logic.

As another example of this open-form API design, yaahc mentioned in a PM wanting this relationship included in a hint in the help, like defaults, envs, and possible values. I had two idea for this

@epage epage added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. A-builder Area: Builder API A-help Area: documentation, including docs.rs, readme, examples, etc... labels Jan 20, 2022
@epage
Copy link
Member

epage commented Jan 20, 2022

experimented with out of tree rather than needing to bake it into clap directly.

As a small clarification on my vague statements, we are looking at not having everything baked directly into clap::App::get_matches but allow passing in logic through trait objects. These trait impls can be defined in-tree or out-of-tree. General ones, like what I talked about above, could be in the clap crate. If someone wanted to customize things, like optimizing for this specific feature request, that would probably be kept out-of-tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state.
Projects
None yet
Development

No branches or pull requests

2 participants