Bil*_*ain 6 haskell autocomplete bash-completion
Haskell 的cmdArgs包提供了命令选项解析.
基于此页面的文档http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Explicit.html#g:4及其来源http:/ /hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/src/System-Console-CmdArgs-Explicit-Complete.html#Complete
它似乎能够支持bash完成,但我无法使用解析器的隐式版本.http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Implicit.html
有没有人有这样做的例子?
编辑添加了更好的示例
如果我有这个程序
{-# LANGUAGE DeriveDataTypeable #-}
import System.Console.CmdArgs
data Sample = Sample {hello :: String}
deriving (Show, Data, Typeable)
sample = Sample{hello = def}
main = print =<< cmdArgs sample
Run Code Online (Sandbox Code Playgroud)
与解析以下选项
The sample program
sample [OPTIONS]
Common flags:
-h --hello=ITEM
-? --help Display help message
-V --version Print version information
Run Code Online (Sandbox Code Playgroud)
如何使用cmdArgs的bash完成功能?
要使用bash完成,请编译上面的程序sample,然后sample放在你的$PATH运行中:
sample --help=bash > sample.comp
source sample.comp
Run Code Online (Sandbox Code Playgroud)
您现在可以输入sample --ver,按Tab键,它将完成sample --version.
有一对情侣在完成infelicities,特别程序必须在你的$PATH,如果你使用的是Windows,你需要运行sample.comp通过dos2unix.它也完全没有文档,应该由程序包作者修复.