ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

Generating bash completion #12

Open dlthomas opened 10 years ago

dlthomas commented 10 years ago

Wondering if you've given any thought to this. It seems like there's room for something awesome. I assume it would go in a separate package. I can see about tackling it myself (and will, when it rises sufficiently high on my list of projects) but 1) I don't want to step on your toes if you have plans there, and 2) I'm happy for any thoughts or guidance you might have if I do sit down to it.

Thanks for the great package!

ndmitchell commented 10 years ago

I think bash completion should definitely be in the same CmdArgs package, and if you're happy to help, that's great - I'm primarily a Windows user, so it's not something I actively use. As it happens, CmdArgs already has "some" bash completion. Taking the example of hlint, you can run:

hlint --help=bash

And that spits out a shell script. If you write that shell script to a file, then source it, you (might) get completions for HLint. There are little bits of docs in a few places:

The basic idea is that the command line argument processing is quite complex, so rather than trying to dump it into a shell script, I instead provide a complete function in CmdArgs that does the completions, then have the shell script call it via processArgs and marshal the results back into the format the shell script wants them.

I worked on this feature quite a while ago. I don't quite know what state I got it to (I think either working, or mostly working), but I don't think I ever told anyone about it. If you want to try it out, see how it works, I'd love to know.

dlthomas commented 10 years ago

Ah, missed that, awesome. I'll play around and see if there's any changes I want to make. Thanks for the great library! :)

ndmitchell commented 7 years ago

At worst, this should be documented, but I suspect there's more work to do as well.