Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

make Optional flag handling consistent #142

Open
BurntSushi opened this issue Oct 6, 2015 · 3 comments
Open

make Optional flag handling consistent #142

BurntSushi opened this issue Oct 6, 2015 · 3 comments

Comments

@BurntSushi
Copy link
Member

Reported by @SuperFluffy #128 (comment)

It is only necessary for f64 but not for, say, u64. In fact, I have the following struct where both flags are optional, just that I need to wrap the f64 in an Option<>, which is not necessary for u64.

struct Args {
    flag_foo: Option<f64>,
    flag_bar: u64,
}

I'd prefer if there was some consistency in this by either not having to wrap the f64 or having to wrap the other primitives as well.

@BurntSushi BurntSushi mentioned this issue Oct 6, 2015
@BurntSushi
Copy link
Member Author

The conservative choice here is to permit f64 for optional arguments/flags by filling it in with a default value of 0. I find this unfortunate, because I'd rather be forced to use an Option to express an optional parameter.

@BurntSushi
Copy link
Member Author

For now, the example presented should use Option<u64> instead of u64 to get consistent behavior.

@BurntSushi
Copy link
Member Author

Another possibility is to use Docopt's default value feature, e.g., [default 0.0], which should get filled in automatically without the need of Option<f64>.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant