我尝试将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; }
答案 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