libre-man / unix-opts

Unix-style command line options parser
MIT License
107 stars 13 forks source link

Make it possible to mark flags as required #6

Closed libre-man closed 7 years ago

libre-man commented 7 years ago

A lot of my programs have required flags such as usernames. For these programs it is useful to mark options as required.

mrkkrp commented 7 years ago

Thanks, this is a good feature to have!

I've just enabled Travis CI for this repo, could you please rebase against current master?

Also, could you try to avoid changing indentation unless you really change indented code, it would make reviewing a lot easier.

mrkkrp commented 7 years ago

Applied as 5d59869fe965951e804fab821ede5fb0b084331f.

libre-man commented 7 years ago

Oh sorry I forgot about your comments. Sorry for the indentation, my Emacs autoindents my code as I type.

mrkkrp commented 7 years ago

My Emacs does that too, the trick is to evaluate the macro first so indentation code in slime becomes aware of it. Then it indents it correctly.

libre-man commented 7 years ago

By the way isn't it a better idea to also give the correct arguments to the error so that a possible handler can do something different if arguments like --help are passed?

mrkkrp commented 7 years ago

--help is not an argument, it's a flag (option). If you mean that the library should handle cases like --required-option --help and figure out that --help is not value of option but a separate flag, I'd say it's too hairy a design.

libre-man commented 7 years ago

No what I mean is that a program might have a required option but also a help flag. You probably don't want to show an error to the user if the help flag is passed even if the required argument is not given. At the moment the required error does not specify the arguments and flags that are given, so it is not possible to check if a flag like help is passed during the handling of the error.

mrkkrp commented 7 years ago

Yeah, that could be improved.