-
Notifications
You must be signed in to change notification settings - Fork 480
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
Parse Single dash option as dashdash option #685
Comments
The As for treating a single The only way to do what you're wanting to do is to pre-process your incoming args before handing them to the Parser, so that all the single-hyphen args that don't fit the getopt style are turned into double hyphens. I'd suggest something like this: var processedArgs = args.Select(arg => arg.Replace("-Url", "--Url").Replace("-monoapp", "--monoapp").Replace("-Ctx", "--Ctx")); Or better yet, use regular expressions and put a Then you'll be able to hand the BTW, the |
Arf ok... So do you know and alternative library which can help me ? Ps: thanks for all of those explanation 😉 |
What is the OS you are using this commandline options? |
@rmunn
|
I tried @moh-hassan The main target are windows 10 x64 but can also have some Windows server. |
As you are acting as a middleware, you have a control to get your args as Gnu standard and then converting these options to match the external software/API. |
Of course I can manage the conversion of options, this is my work :D I will try to find a generic way to convert the command line Edit: I find a quite simple generic way seem to work well. Do you see any possible problem with this ? args = args.Select(arg => Regex.IsMatch(arg, "^-\\w{2,}") ? "-" + arg : arg ).ToArray(); |
+1. It would be nice to support other standards. |
For windows, its always been a problem that windows used / as the argument discriminator when used in POSIX situations. How does the library differentiate between creating a new directory /Url or downloading for the /Url specified? Additionally, when you start introducing single dash options for long names, you create ambiguities that are unable to be resolved. For example, if I have three boolean options, Supporting different standards is beyond the scope of this project. The CommandLineParser library is entirely designed to support the GNU getopt standard of argument parsing. If somebody decides to fork the project and continue to utilize the core parsing, property resolution and value placements, thats fine. The GNU getopt standard is tried and true, has existed for over two decades, and it pretty reliable, even by current standards. I personally do not want to begin to support the myriad of ambiguous scenarios that arise from mixing and matching different standards. ...Just my 2cents... |
I published a PR that brings the option to define the parsing behavior for command line options, whether to use single or double dashes: #767 Maybe you could consider this PR to raise the satisfaction for some of your library consumers. |
I am also writing a parser and have exactly the same issue. I tried to process command line to change single dash to double dashes, but occasionally I find a new test case for which change is not correct :) also I was thinking of a way to disable flag merging to not have ambiguity like -long <=> -l -o -n -g. |
I would like to comment in support of this planning. In my case, I am trying to use CommandLine for a Unity project, where a single dash in front of parameter names is unfortunately what is used. For now, I seem to be fine with the regex based conversion that is mentioned here: #685 (comment) |
Hi everyone,
I'm trying to parse a command line (imposed, no way to change it) which are like
As you can see, there is a lot of different case:
And I wasn't able to parse it because it seems that when there is just a dash option, it mustn't be a long name. ( I have a lot of
UnknownOptionError
which seem to come from that)So I have a very simple code to test
So I did something wrong ? There is a way to parse this command line ?
Thanks in advance for your help
The text was updated successfully, but these errors were encountered: