commandlineparser / commandlineparser/commandline

Cannot parse "1"

Đang mở
#797 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
4.8k
Fork
478
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.