Skip to content

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

@yaahc

Description

@yaahc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-builderArea: Builder APIA-helpArea: documentation, including docs.rs, readme, examples, etc...C-enhancementCategory: Raise on the bar on expectationsS-experimentalStatus: Ongoing experiment that does not require reviewing and won't be merged in its current state.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions