commandlineparser / commandlineparser/commandline

Cannot parse "1"

未關閉
#797 6 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C#
星號
4.8k
分支
478
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。