[英]Read (unnamed) argument in console line
As ConsoleFx seems to be progressing too slow (bummer, it had much potential) and showing too many breaking changes every build, I decided to switch to Mono.Options for my commandline parsing needs. 由于ConsoleFx的执行速度似乎太慢(糟糕,它有很大的潜力),并且每次构建都显示太多重大更改,因此我决定切换到Mono.Options来满足命令行解析的需要。
My OptionSet is built in the following method 我的OptionSet是通过以下方法构建的
private static OptionSet BuildOptionSet()
{
OptionSet optionSet = new OptionSet()
.Add("?|help|h", "Prints out the options", option => help = option != null)
.Add("w|wait", "Waits for any key after finished processing", option => wait)
return optionSet;
}
All tutorials I find, deal with options and how to capture them, but arguments are never mentioned. 我找到的所有教程都涉及选项以及如何捕获它们,但从未提及过参数。
The following call for example 以下电话为例
c:\>test.exe brandCode1 brandCode2 /w
Should put wait on true and give me two arguments with values brandCode1 and brandCode2. 应该等待true,然后给我两个参数,分别是brandCode1和brandCode2。 How can I capture them in a clean way from the args[] ?
如何从args []中以干净的方式捕获它们?
Is this not possible with Mono.Options? Mono.Options无法做到这一点吗?
From what I can tell from reading the docs, you need to call OptionSet
's parse
method at some point. 从我阅读文档可以看出,您有时需要调用
OptionSet
的parse
方法。 When you do, it processes your actions and returns "A List<string>
containing all unhandled arguments." 完成后,它将处理您的操作并返回“包含所有未处理参数的
List<string>
”。
Unfortunately, you also need to pass it the main method's argument to get this to work. 不幸的是,您还需要向它传递main方法的参数才能使它起作用。
List<string> extra = optionSet.Parse(args);
Edit: In case my link (still) isn't working, parse should link to http://www.ndesk.org/doc/ndesk-options/NDesk.Options/OptionSet.html#M:NDesk.Options.OptionSet.Parse%28System.String,NDesk.Options.OptionContext%29 编辑:如果我的链接(仍然)不起作用,则解析应链接到http://www.ndesk.org/doc/ndesk-options/NDesk.Options/OptionSet.html#M:NDesk.Options.OptionSet。解析%28System.String,NDesk.Options.OptionContext%29
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.