cmdArgs bash完成

时间:2013-05-31 18:06:52

标签: haskell autocomplete bash-completion

Haskell的cmdArgs package提供命令选项解析。

基于文档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

解析以下选项

The sample program

sample [OPTIONS]

Common flags:
  -h --hello=ITEM
  -? --help        Display help message
  -V --version     Print version information

如何使用cmdArgs的bash完成功能?

1 个答案:

答案 0 :(得分:6)

要使用bash完成,请将上述程序编译为sample,将sample放在$PATH上,然后运行:

sample --help=bash > sample.comp
source sample.comp

您现在可以输入sample --ver,按标签,它将完成sample --version

完成时会有一些不足之处,特别是程序必须在$PATH上,如果您在Windows上,则需要sample.compdos2unix。它也完全没有文档,应该由程序包作者修复。