commandlineparser / commandlineparser/commandline

Cannot parse "1"

Abierto
#797 6 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C#
Estrellas
4.8k
Forks
478
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

E.g. "--KEEP_ALIVE_OPTION=1".

This treats by the parser as no value:
_Option 'keep_alive_option" has no value.
Required option 'keep_alive_option' is missing._

```
public class KeepAliveOptions
{
[Option(Required = true)]
public string KEEP_ALIVE_OPTION { get; set; }
[Option(Required = true)]
public string LOGIN_URL { get; set; }
[Option(Required = true)]
public string ADVISOR_PASSWORD { get; set; }
[Option(Required = true)]
public string COMPANY_NUMBER { get; set; }
[Option(Required = true)]
public string OUT_DIR { get; set; }
[Option(Required = true)]
public string UserID { get; set; }
[Option(Required = true)]
public string Password { get; set; }
}
```

```
public ParserResult Parse(string[] args) where T : IScriptOptions
{
Parser parser = new(s =>
{
s.CaseSensitive = false;
s.IgnoreUnknownArguments = true;
s.HelpWriter = Parser.Default.Settings.HelpWriter;
});

var scriptOptions = new List();

for (int i = 0; i < args.Length; i++)
{
string option = $"--{args[i].TrimStart('/')}";

scriptOptions.Add(option);
}

return parser.ParseArguments(scriptOptions);
}
```

```
var result = Parse(args)
.WithParsed(keepAliveOptions => options = keepAliveOptions)
```

Tried to change KEEP_ALIVE_OPTION type to int, it doesn't change anything

Fiddle: https://dotnetfiddle.net/vbujQc

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.