markhibberd / pirate

Non-horrible command line parsing.
https://github.com/markhibberd/pirate
BSD 3-Clause "New" or "Revised" License
42 stars 10 forks source link

Add support for bash/zsh completions. #4

Open markhibberd opened 10 years ago

charleso commented 10 years ago

Perhaps a dumb question - is this only possible if we do something like generate the bash/zsh files (and I guess add an SBT plugin to make that easy)?

markhibberd commented 10 years ago

There are two ways, probably only one of which is practical given java start-up times.

  1. a generic completion script that calls pirate with a specific flag to change the output to the right format.
  2. pretty much what you said, add a mechanism to generate the scripts during the build process.

The problem with (1) is startup time but given some tuning and -client or jdk8 it is possible,

The problem with (2) it is hard to encode the dynamic completions (i.e. context dependent completion, e.g. after I enter a sub command what are the valid flags).

Not sure of best, but it would be really nice.

charleso commented 10 years ago

I was looking around for examples of Java/Scala libraries that did something similar but I couldn't find anything (I might be blind though). I agree it would be great.

markhibberd commented 10 years ago

This is a haskell library that does it using a fairly similar structured parser to the applicative one in pirate: http://hackage.haskell.org/package/optparse-applicative-0.9.0/docs/src/Options-Applicative-BashCompletion.html#bashCompletionParser