cmdArgs bash completion

筅森魡賤 提交于 2019-12-06 01:56:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16863284/cmdargs-bash-completion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!