C# 的 GetOpt 库
我正在寻找 C# 的 getopt 库。 到目前为止,我找到了一些(phpguru,XGetOptCS, getoptfordotnet),但这些看起来更像是未完成的尝试,仅支持 C 的 getopt 的一部分。 有完整的 getopt C# 实现吗?
I'm looking for a getopt library for c#. So far I found a few (phpguru, XGetOptCS, getoptfordotnet) but these look more like unfinished attempts that only support a part of C's getopt.
Is there a full getopt c# implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我的一个朋友建议 docopt.net,
基于 Node.JS 的 docopt 库的命令行参数解析库。 它使用起来非常简单,但很先进,并根据您编写的帮助字符串解析参数。
以下是一些示例代码:
您可以在第一个链接和此处找到它的文档(包括其帮助消息格式) 。
希望它能帮助别人!
A friend of mine suggested docopt.net,
a command-line argument parsing library based on the docopt library for Node.JS. It is very simple to use, yet advanced and parses arguments based on the help string you write.
Here's some sample code:
You can find documentation for it (including its help message format) at both the first link and here.
Hope it helps someone!
郑重声明,NUnit 在 src\ClientUtilities\util\CommandLineOptions 中包含一个简单的单文件命令行解析器。 cs (请参阅位于
src\ConsoleRunner\nunit-console
下的ConsoleRunner.cs
和Runner.cs
中的示例用法)。 文件本身不包含任何许可信息,以及指向其“上游”的链接似乎已经死亡,因此其法律地位不确定。解析器支持命名标志参数(如
/verbose
)、带值的命名参数(如/filename:bar.txt
)和未命名参数,即,很多风格Windows 脚本宿主如何解释它们。 选项可能以/
、-
和--
为前缀。For the record, NUnit includes a simple one-file command-line parser in
src\ClientUtilities\util\CommandLineOptions.cs
(see example usage inConsoleRunner.cs
andRunner.cs
located undersrc\ConsoleRunner\nunit-console
). The file itself does not include any licencing information, and a link to its "upstream" seems to be dead, so its legal status is uncertain.The parser supports named flag parameters (like
/verbose
), named parameters with values (like/filename:bar.txt
) and unnamed parameters, that is, much in style of how Windows Scripting Host interprets them. Options might be prefixed with/
,-
and--
.Miguel de Icaza 对 Mono.Options 赞不绝口。 您可以使用 nuget 包,或者只复制 单个 C# 源文件 到您的项目中。
Miguel de Icaza raves about Mono.Options. You can use the nuget package, or just copy the single C# source file into your project.
下面是 getopt 的 .NET 实现: http://www.codeplex.com/getopt
Here is a .NET Implementation of getopt: http://www.codeplex.com/getopt
对于后代:
CommandParser 是另一个具有 BSD 许可证的
For posterity:
CommandParser is another one with a BSD license
这里是我写的,它有效相当不错,并且以少量的代码提供了相当多的功能。 然而,它不是 getopts,但它可能适合您的需求。
请随意问一些问题。
Here is something I wrote, it works rather nice, and has quite a lot of features for the tiny amount of code. It is not getopts however, but it may suit your needs.
Feel free to ask some questions.
它不是 getopt,但您可以尝试 NConsoler。 它使用属性来定义参数和操作。
It's not getopt, but you might try NConsoler. It uses attributes to define arguments and actions.
Mono 项目有(或者更确切地说有)一个基于属性的项目,但最后我检查它被标记为过时。 但由于它是开源的,您也许可以提取代码并自己使用。
The Mono Project has (or rather had) one based on attributes, but last I checked it was marked as obsolete. But since it's open source, you might be able to pull the code out and use it yourself.