Skip to content

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

Description

@keiichiw

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());

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions