question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parse Single dash option as dashdash option

See original GitHub issue

Hi 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)

image

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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
MichaeIDietrichcommented, Aug 4, 2021

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.

2reactions
moh-hassancommented, Aug 19, 2020

@rmunn We can plan to extend the library to support other standard commandline options beside GNU standard like:

  • Using single dash only as Posix standard/ Powershell and Unity Engine.
  • Using forward slash to support legacy windows standard.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found