Comments (8)
I have been looking at how cmdargs
does this, and I think I understand how it works.
The only thing that I'm not sure about is how it handles (if at all) the generation and installation of the completion script.
My plan is to implement a combinator that adds two internal
commands to a parser:
bash-completion-query
: that takes the completion parametersCOMP_WORDS
andCOMP_CWORD
, and returns the possible completions for a given parserbash-completion-script
: that returns a completion script using the above option to implement completion
The author of a program using optparse-applicative
would then have to generate the script using bash-completion-script
(every time the parser changes) and include it in the package as a data file. Ideally, the process could be automated in cabal.
Does that look like a sensible plan? Any other suggestions?
from optparse-applicative.
Sounds good. Not sure why you'd need to update the script with the parser though, if it's just calling to --bash-completion-query
anyway?
from optparse-applicative.
Yeah, you're right. The script would actually only depend on the name of the program, so maybe there's no need for the bash-completion-script
command.
from optparse-applicative.
That flag is still nice because you can have a bashrc like, eval $(foo --bash-completion-script)
or pipe it to your bashrc to install.
from optparse-applicative.
Bash completion is done. There are still a few missing details, but the basic functionality is there. Full details here.
from optparse-applicative.
Cool stuff!
Would it be difficult to make it possible to pass in things to be accessible from a completer
function? I'm using the dyre package for configuration and accessing the config from just an IO action isn't trivial to my knowledge. I'd need the config for connecting to acid-state which might be useful for completing some arguments.
I suppose in the worst case I could make a global IORef, but would be nice to be able to avoid such hacks.
from optparse-applicative.
I'm not sure I understand what the problem is exactly.
Assuming your initialization code comes after execParser
, you can freely run it again from any completer, since the program will exit before returning from execParser
, when invoked by the completion mechanism. In fact, you can think of a completer as an alternative main
.
If you're running the initialization code before execParser
, then you can just pass the extra arguments in the closure of the completer.
from optparse-applicative.
Uh, of course. Not sure what I was thinking there. ☺
from optparse-applicative.
Related Issues (20)
- Showing help on empty with inline subcommands HOT 6
- Listification (like `some1`) does not change the `metavar` to plural HOT 2
- Add ability to group aliases in --help HOT 2
- Offer a positional parser HOT 2
- Parse in interactive program HOT 2
- Export `requote` from `Options.Applicative.Builder.Completer` HOT 2
- Options shown in Global section can include unreachable alternatives. HOT 4
- Add Semigroup/Monoid to Parser HOT 7
- Ignore unused flags HOT 2
- Parser HOT 1
- (Question) Is there value in storing CLI output in a text file and using it as a golden test? HOT 1
- Is it possible to automatically show in help which values are valid for an option? HOT 3
- Stack executable built against `optparse-applicative-0.17.1.0` 'hangs' HOT 20
- Ansi annotations aren't being rendered.
- How do I print help info with colored command names? HOT 14
- v0.18: `text` no longer exported from `Options.Applicative.Help.Pretty` HOT 4
- Default command and command alias
- Apply style for command groups HOT 3
- partitioning args HOT 3
- Support for ospath/osstring
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from optparse-applicative.