commandlineparser / commandlineparser/commandline

Parse Single dash option as dashdash option

Aberta
#685 12 comentários 3 reações 0 responsáveis Ver no GitHub
Linguagem predominante
C#
Estrelas
4.8k
Forks
478
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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](https://user-images.githubusercontent.com/1184332/90609441-50b4e380-e204-11ea-9d14-e7b7de205cd3.png)

So I have a very simple code to test

```C#
[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(args).WithParsed(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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Start at the Main method and Parser configuration shown in the issue, then reproduce the supplied command line with the example option declarations. Compare how single-dash long options and separators are parsed, including the resulting UnknownOptionError values. Done means the sample command line parses successfully and populates Url, AppName, Env, Monoapp, and Ctx.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
csharp
Domínio
cli
Tipo de issue
Funcionalidade
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.