命令行分析器库 - 布尔参数

时间:2016-03-08 17:19:56

标签: c# nuget-package command-line-parser

我尝试将boolean参数传递给控制台应用程序,并使用Command Line Parser Library处理该值。

[Option('c', "closeWindow", Required = true, HelpText = "Close the window.")]
public bool CloseWindow { get; set; }

我尝试将参数传递为

-c false
-c False
-c "false"
-...

没有差异,每次尝试都会"true"为值。

有谁能告诉我如何传递参数以获取布尔false值?

为了避免可能的问题,有一个正确传递的字符串选项:

[Option('s', "system", Required = true, HelpText = "Any help text")]
public string System { get; set; }

2 个答案:

答案 0 :(得分:19)

您无需添加import Dmyab as other_dmyab [...] other_dmyab.run1() True。使用False将评估为-c。不使用它将评估为True。文档中的某处有一个False示例,用于详细输出。但我现在找不到它。我猜布尔选项不需要-v

答案 1 :(得分:1)

bool?表现出您想要的方式

与:

[Option('c', "closeWindow", Required = true, HelpText = "Close the window.")]
public bool? CloseWindow { get; set; }

结果将是:

-c false // -> false
-c true  // -> true
-c       // -> error
         // -> error if Required = true, null otherwise