commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Add setting to interpret options starting with a single dash as long named options

Open MichaeIDietrich opened this issue 3 years ago • 5 comments

This PR adds a setting to use single dashes for command line options.

As several others in issue #685 we wanted to switch to this library, since it is more robust than other libraries available. But due to backwards compatibility we needed to support single dashes instead of double dashes for options else we would break our customer's scripts. So we forked this library and added an option for single dash support and now would like to bring this to the official repo.

There is a new setting OptionsParseMode in ParserSettings

With three modes:

  • Default is identical to the current behavior

Options that start with a double dash must be defined using their full name. (e.g. git rebase --interactive) Options that start with a single dash are interpreted as list of short named options. (e.g. git clean -xdf)

  • SingleOrDoubleDash

Options that start with a single or double dash are interpreted as short or full named option. (e.g. git rebase --interactive or git rebase -interactive or git rebase --i or git rebase -i, but git clean -xdf would no longer be possible)

  • SingleDashOnly

Options that start with a single dash are interpreted as short or full named option. (e.g. git rebase -interactive or git rebase -i ) Options that start with a double dash are considered as an invalid input. (e.g. git rebase --interactive would no longer be possible)

It would be great if you could consider this feature, since there are several library consumers that are looking for this option.

MichaeIDietrich avatar Aug 03 '21 11:08 MichaeIDietrich

Thank you for submitting.

Your pull request looks comprehensive, and good job with adding the tests. I believe this warrants a minor version bump to 2.10

I'm a little apprehensive about deviating from the original getopt specs but I do see the benefit of migration (ahem Nuget.exe) and similar.

ericnewton76 avatar Sep 10 '22 17:09 ericnewton76

Oh great, it would be really nice if this could be merged, so there is no need for our dev team to maintain a local fork anymore. I will have another look on this PR next week. If I remember correctly, there was bug we have already fixed in our local fork. If so, I'll update the PR and report back. 👍

MichaeIDietrich avatar Sep 10 '22 20:09 MichaeIDietrich

OK, I updated the PR. There were hard coded occurrences of --help and --version that I missed before. But now they are also handled correctly in respect to the used mode.

By the way this new mode is almost in use for one year in our business application and we received no issues from our customers, so it is kind of tested externally already. :)

So from my perspective this PR is ready to be merged, if you don't have any further suggestions.

MichaeIDietrich avatar Sep 12 '22 09:09 MichaeIDietrich

Any chance this can be reviewed and merged? It would be a very much welcome improvement!

josesimoes avatar Nov 29 '22 15:11 josesimoes

This PR does exactly what we want to achieve in our application. It would be great if single dashes would be an option in the CommandLine library. We really like the functionality and how this library provides an easy to use and easy to maintain command line support. Unfortunately we also have the hard requirement to use single dashes.

Merging this would be great :-)

daniel-flemming avatar Jul 11 '23 09:07 daniel-flemming