Parse Single dash option as dashdash option
See original GitHub issueHi everyone,
I’m trying to parse a command line (imposed, no way to change it) which are like
myexe.exe -Url=https://blabla.com/ --AppName=val1 -e testCase -monoapp Open -Ctx "default ctx"
As you can see, there is a lot of different case:
- Some single dash option with a long name with space as separator
- Some single dash option with a long name with equals as separator
- Single dash option with short name with space as separator
- …
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
[Verb("Open")]
public class CommandLineOptions
{
[Option("Url", Separator = '=')]
public string Url { get; set; }
[Option("AppName", Separator = '=')]
public string AppName { get; set; }
[Option('e',"env", Separator = ' ')]
public string Env { get; set; }
[Option("monoapp")]
public bool Monoapp { get; set; }
[Option("Ctx", Separator = ' ')]
public string Ctx { get; set; }
}
....... In another file but in the same assembly
static void Main(string[] args)
{
var commandLineOptions = new CommandLineOptionsOpen();
var parser = new Parser(with =>
{
with.EnableDashDash = false; // tested as true, same result
with.IgnoreUnknownArguments = false;
});
var parseResult = parser.ParseArguments<CommandLineOptionsOpen>(args).WithParsed<CommandLineOptionsOpen>(result => commandLineOptions = result);
System.Console.WriteLine(parseResult.Tag); // NotParsed
System.Console.WriteLine(commandLineOptions.Url); // Null like all others values
}
So I did something wrong ? There is a way to parse this command line ?
Thanks in advance for your help
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:12 (2 by maintainers)
Top Results From Across the Web
python - Having options in argparse with a dash
I want to have some options in argparse module such as --pm-export however when I try to use it like args.pm-export I get...
Read more >using single dash with long name [closed]
I know that a single dash goes with one character when we set options using getopt or optparse. but is there anyway to...
Read more >What's the difference betwen the single dash and double ...
In this case the double dashes keep the options for each program separated and allows the built-in parser's error handling to work as...
Read more >getopt(1): parse command options | Linux Man Page
getopt is used to break up (parse) options in command lines for easy parsing by shell procedures, and to check for valid options....
Read more >Git - git-rev-parse Documentation
--keep-dashdash. Only meaningful in --parseopt mode. Tells the option parser to echo out the first -- met instead of skipping it. --stop-at-non-option.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@rmunn We can plan to extend the library to support other standard commandline options beside GNU standard like: