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

Can't unset a global setting #1183

Closed
anna-is-cute opened this issue Feb 14, 2018 · 1 comment
Closed

Can't unset a global setting #1183

anna-is-cute opened this issue Feb 14, 2018 · 1 comment

Comments

@anna-is-cute
Copy link

Affected Version of clap

2.29.4

Expected Behavior Summary

Unsetting a setting that has been made global causes it to not affect the arg or subcommand.

Actual Behavior Summary

The setting still applies.

Sample Code or Link to Sample Code

extern crate clap;

use clap::{App, Arg, SubCommand, AppSettings};

fn main() {
  let args = App::new("app")
    .global_setting(AppSettings::ArgRequiredElseHelp)
    .arg(Arg::with_name("arg1")
      .takes_value(true)
      .multiple(false)
      .required(false))
    .subcommand(SubCommand::with_name("sub")
      .unset_setting(AppSettings::ArgRequiredElseHelp)
      .arg(Arg::with_name("arg2")
        .takes_value(true)
        .multiple(false)
        .required(false)))
    .get_matches();
  println!("{:#?}", args);
}

In the subcommand, the only arg is optional, so I don't want ArgRequiredElseHelp, but the vast majority of other subcommands (in my use case) all benefit from ArgRequiredElseHelp.

I can see this is because it's unset in settings but not g_settings. Should unset_setting do both or should unset_global_setting be added? I'd be happy to PR if I knew which direction to go in.

@kbknapp
Copy link
Member

kbknapp commented Feb 14, 2018

You're spot on, and actually in v3 I side step this slightly by using (un)set and (un)set_global and actually differentiating the two. For v2 I think it's going to have to stay as is, because I fear changing it would be breaking change (i.e. if there are people relying the current behaviour).

I'm going to close this, however when v3 is released if this issue pops up please feel free to re-address it.

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

No branches or pull requests

2 participants