Giter Club home page Giter Club logo

Comments (8)

pcapriotti avatar pcapriotti commented on August 17, 2024

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 parameters COMP_WORDS and COMP_CWORD, and returns the possible completions for a given parser
  • bash-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.

dag avatar dag commented on August 17, 2024

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.

pcapriotti avatar pcapriotti commented on August 17, 2024

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.

dag avatar dag commented on August 17, 2024

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.

pcapriotti avatar pcapriotti commented on August 17, 2024

Bash completion is done. There are still a few missing details, but the basic functionality is there. Full details here.

from optparse-applicative.

dag avatar dag commented on August 17, 2024

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.

pcapriotti avatar pcapriotti commented on August 17, 2024

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.

dag avatar dag commented on August 17, 2024

Uh, of course. Not sure what I was thinking there. ☺

from optparse-applicative.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.