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

default_value confuses bool flags #80

Closed
vorner opened this issue Mar 11, 2018 · 1 comment
Closed

default_value confuses bool flags #80

vorner opened this issue Mar 11, 2018 · 1 comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@vorner
Copy link

vorner commented Mar 11, 2018

Hello

If I have a bool flag and set default_value = "false", it defaults to true. Even though it works if I don't set any default value, this is a bit confusing:

#[macro_use]
extern crate structopt;

use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opts {
    /// Flag that is always true even when not set explicitly.
    #[structopt(short = "f", long = "flag", default_value = "false")]
    flag: bool,
}

fn main() {
    println!("{:?}", Opts::from_args());
}

This prints (if I don't pass any arguments at all):

Opts { flag: true }

I'd suggest to this either work as expected (eg. defaulting to false) or erroring,

This is structopt 0.2.5.

@TeXitoi
Copy link
Owner

TeXitoi commented Mar 11, 2018

It can't work as expected. Erroring in this case seems a good thing. We should look at others methods that are meaningless with book, as env

@TeXitoi TeXitoi added the enhancement We would love to have this feature! Feel free to supply a PR label Mar 12, 2018
mre added a commit to tinysearch/tinysearch that referenced this issue Apr 29, 2019
ppardus pushed a commit to ppardus/tinysearch that referenced this issue Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR
Projects
None yet
Development

No branches or pull requests

2 participants