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 a way of adding "help" flag which works with required options #108

Open
keiichiw opened this issue Dec 15, 2021 · 0 comments · May be fixed by #109
Open

Add a way of adding "help" flag which works with required options #108

keiichiw opened this issue Dec 15, 2021 · 0 comments · May be fixed by #109

Comments

@keiichiw
Copy link

keiichiw commented Dec 15, 2021

I tried to add a --help flag with optflag and a required option.
I expected my_command --help worked, but it didn't because Options::parse() failed due to the lack of the required option.

let mut opts = Options::new();
opts.optflag("h", "help", "Description");
opts.reqopt("r", "required", "Description", "TEST");

let result = opts.parse(&["--help"]);
// Failed with "Required option 'required' missing"!
assert!(result.is_ok());

So, how about have a method to add a help flag, which is an optional and makes parse() work without a required options if it's passed?

let mut opts = Options::new();
opts.helpflag("Description");
opts.reqopt("r", "required", "Description", "TEST");
let result = opts.parse(&["--help"]);
assert!(result.is_ok());
@keiichiw keiichiw linked a pull request Dec 15, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant