问题描述
Haskell的提供命令选项解析。
根据此页面从文档及其来源
它似乎能够支持bash完成,但我无法使用Implicit版本的解析器。
是否有人有没有这样做的例子?
编辑添加了一个更好的例子
如果我有程序
{ - #LANGUAGE DeriveDataTypeable# - }
import System.Console.CmdArgs
data Sample =示例{hello :: String}
deriving(Show,Data,Typeable)
sample = Sample {hello = def}
main = print =<<< ; cmdArgs示例
分析以下选项
<$示例程序
示例[选项]
常用标志:
-h --hello = ITEM
- ? --help显示帮助信息
-V --version打印版本信息
如何使用cmdArgs的bash完成特性?
要使用bash完成,请将上面的程序编译为 sample ,在 $ PATH 上放置 sample ,然后运行:
sample --help = bash> sample.comp
source sample.comp
您现在可以输入 sample --ver ,按Tab键,它会完成到 sample --version 。
完成时有一些不足之处,尤其是程序必须位于 $ PATH 中,如果您在Windows上,则需要运行 sample.comp 到 dos2unix 。它也完全没有记录,它应该由软件包作者修复。
The cmdArgs package for Haskell provide command option parsing.
based on this page from the docs http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Explicit.html#g:4 and its source http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/src/System-Console-CmdArgs-Explicit-Complete.html#Complete
It seem able to support bash completion, but I was not able to made it work with the Implicit version of the parser. http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Implicit.html
Does any one have any example of doing this?
Edit added a better example
if I have the program
{-# LANGUAGE DeriveDataTypeable #-} import System.Console.CmdArgs data Sample = Sample {hello :: String} deriving (Show, Data, Typeable) sample = Sample{hello = def} main = print =<< cmdArgs sample
with parses the following options
The sample program sample [OPTIONS] Common flags: -h --hello=ITEM -? --help Display help message -V --version Print version information
how do use the bash completion feature of cmdArgs?
To use the bash completion, compile the above program as sample, place sample on your $PATH then run:
sample --help=bash > sample.comp source sample.comp
You can now type in sample --ver, press tab, and it will complete to sample --version.
There are a couple of infelicities in the completion, in particular the program must be on your $PATH and if you are on Windows you need to run sample.comp through dos2unix. It is also entirely undocumented, which sHould be fixed by the package author.
这篇关于cmdArgs bash完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!