CmdArgs bash completion

Haskell's cmdArgs package provides command parsing.

on this page from the documentation http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Explicit.html#gready and its source http: // hackage .haskell.org / packages / archive / cmdargs / 0.10.3 / doc / html / src / System-Console-CmdArgs-Explicit-Complete.html # Complete

It seems to support bash completion, but I couldn't get it to work with an implicit version of the parser. http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Implicit.html

Does anyone have an example of this?

Edit added best example

if i have a program

{-# LANGUAGE DeriveDataTypeable #-} import System.Console.CmdArgs data Sample = Sample {hello :: String} deriving (Show, Data, Typeable) sample = Sample{hello = def} main = print =<< cmdArgs sample 

parsing the following parameters

 The sample program sample [OPTIONS] Common flags: -h --hello=ITEM -? --help Display help message -V --version Print version information 

how to use bash completion function for cmdArgs?

+6
source share
1 answer

To use bash completion, compile the above program as sample , put sample on your $PATH , and then run:

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

Now you can enter sample --ver , click the tab, and it will complete before sample --version .

There are several inaccuracies in the end, in particular, the program should be on your $PATH , and if you are on Windows, you need to run sample.comp through dos2unix . It is also completely undocumented, which must be fixed by the package author.

+5
source

Source: https://habr.com/ru/post/946283/


All Articles