rejeep / commander.el

Emacs command line parser
GNU General Public License v3.0
56 stars 8 forks source link

Complex patterns #5

Open rejeep opened 10 years ago

rejeep commented 10 years ago

Allow for more complex patterns for options and commands, for example:

(defun foo (&optional bar baz)
  ...)

(command "foo [bar, baz]" foo)
(defun foo (bar baz)
  ...)

(command "foo <bar, baz>" foo)
(defun foo (&optional bar &rest args)
  ...)

(command "foo [bar, *]" foo)
(defun foo (&optional bar baz &rest args)
  ...)

(command "foo [bar, baz, *]" foo)
(defun foo (bar &optiona baz qux &rest args)
  ...)

(command "foo <bar> [baz, qux, *]" foo)

And more. And same as above for options.

Fuco1 commented 6 years ago

I would also like the ability to do recursive options, i.e. put options to commands, such that I can write for example

cask install --no-dev

but not

cask --no-dev pkg-file

In other words, the options should be scoped to the commands.

Fuco1 commented 6 years ago

This is a good place to steal some ideas, I like the yargs way quite a lot. We can lispify it a bit of course: https://github.com/yargs/yargs/blob/master/docs/api.md

rejeep commented 6 years ago

Holy moly, quite advanced stuff

Fuco1 commented 6 years ago

I'd really like to use commander for https://github.com/emacs-elsa/Elsa so I'm probably going to build at least the things I will need and we can extend later of course :)

rejeep commented 6 years ago

Feel free to add the extensions you want!

Just a bit of warning before you dig into the code. When I wrote this I was working on Ecukes. I needed a CLI option parser for Elisp, but to my surprise there was none. So I wrote this as fast as possible just to get something.

That said, the code I wrote is not the prettiest, I just made it work. The tests should be fairly good though since I figured I might end up refactoring the code at some point (never happened).

Good luck! 🙂