Haskell 中的子命令实用程序
是否有一个简单的方法或库用于在 Haskell 中创建子命令命令行实用程序?
例如,git log
用于记录日志,git status
用于状态等等。像 Python argparse 对子命令的支持 会很棒。
Is there a simple recipe or library for creating a subcommand command line utility in Haskell?
E.g. git log
for logging, git status
for status et cetera. Something like Python's argparse's support for subcommands would be fantastic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我自己还没有使用过它,但是请看一下 CmdArgs 包。
I haven't used it myself yet, but take a look at the CmdArgs package.
您了解黑客吗?只需查找
args
,您就会看到cmdargs
(易于使用,可以说是最流行的解决方案),parseargs
(不太神奇,实际上可能适用于一个非 GHC 编译器,也易于使用)和simpleargs
(我没有使用过这个)。可能还有其他文件,但您应该查看黑线鳕文档并决定哪一个最适合您的需求。Do you know about hackage? Just look for
args
and you seecmdargs
(easy to use, arguably the most popular solution),parseargs
(less magic, might actually work with a non-GHC compiler, also easy to use), andsimpleargs
(I've not used this one). Others are probably out there, but you should look at the haddock documents and decide which one seems most fitting for your needs.编写一个简单的主应用程序,仅检查其第一个参数字符串,并根据该字符串进行指定。它将后续参数传递给实际处理请求的程序(
log
或status
)。将模块中的常用功能分组为可用,并且您已经有了一个整洁的框架来编写新的“模块”,因为它们有时被称为“模块”。Write one simple main application that only checks for its first argument string, and delecates basing on that. It will pass the subsequent arguments to the program that actually handles the requests (the
log
orstatus
). Group common functionality in modules to be available and you already have a tidy framework to write new "modules" as they sometimes are called.