Hacker News new | ask | show | jobs
by thechao 2654 days ago
I used docopt in production for years, before switching off of it.

My main issues were that the author of docopt doesn't know anything about language grammars & parsing. That's fine — we all start somewhere. But he insists that defining a grammar (and having a rational parser) aren't useful or even possible! If, instead, there were a normative spec (and this requires only the slightest change to edge-cases that aren't tested by his test-suite, anyways), then it'd be possible to really roll out a much more robust docopt than what currently occurs.

With a grammar you'd be able to roll out AST=>AST transforms, and update the parsing strategy of the command lines, i.e., portability between CLI flavors between new/old style POSIX, Windows, etc. You'd have the ability to do i18n, you could catch errors both in the docopt spec of your parser, and in the parsing of the command line options, etc.

2 comments

I've started with a fork of Docopt, but then I realized the exact same thing - the maintainers didn't use the best parsing practices, so I've just deleted the fork and started Docli. If you follow the tutorial you will see that you can print the AST produced by Docli's parser :D.
So did you end up making something better? I’ve been using docopt for years but I’ll gladly consider switching to a better alternative.
May I suggest you give https://github.com/jawher/mow.cli a look/try ?

Disclaimer: I'm the author of mow.cli ;)

All of my publicly available thoughts are here: https://github.com/jaroslov/docoptc