cmdargs icon indicating copy to clipboard operation
cmdargs copied to clipboard

Generating bash completion

Open dlthomas opened this issue 10 years ago • 3 comments

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!

dlthomas avatar Jul 30 '14 23:07 dlthomas

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:

  • http://hackage.haskell.org/package/cmdargs-0.10.9/docs/System-Console-CmdArgs-Explicit.html#v:HelpFormatBash
  • http://hackage.haskell.org/package/cmdargs-0.10.9/docs/System-Console-CmdArgs-Explicit.html#v:processArgs
  • http://hackage.haskell.org/package/cmdargs-0.10.9/docs/System-Console-CmdArgs-Explicit.html#v:complete

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.

ndmitchell avatar Jul 31 '14 20:07 ndmitchell

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

dlthomas avatar Aug 01 '14 01:08 dlthomas

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

ndmitchell avatar Dec 26 '16 19:12 ndmitchell