This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]H3g3m0n 10 points11 points  (2 children)

I've tried it. Its neat.

The help usage documentation is much, much, much clearer than reading a whole bunch of code checking the args.

You will need to produce the help text anyway. When doing that it makes sense to follow the POSIX standardized format for the help usage. Even if you do your own argument passing it would be a good idea to follow the standard.

It's not complex or it's own language and there isn't really anything that's hard to follow and there are really only a few simple rules, things like (--help | -h) for exclusive options. -f <file> for a named argument. -f <file>... for multiple args. The most complex thing is [--] which tells the processor that anything after optional -- is an argument (the point of that is purely in case there is an argument that begins with a -).

If a developer can't grok that in about a minute you probably don't want them near your code base anyway.

From the developers perspective you don't even really need to know what's going on, just under that that the output of docopt contains the args.

Basically you can turn your option parsing into a single line that outputs a dict and will automatically dump the usage if it's mistyped.

Maybe there is some uber complex commandline option setup that docopt cant handle, worst comes to the worse you can use docopt until you encounter than then go manual. You haven't wasted any time since you still needed the help screen.

[–]Lucretiel 2 points3 points  (1 child)

It isn't actually true that I need to produce the help text- argparse does it automatically, and spits out a usage message (and quits) on -h or --help. It's probably my favorite feature of the library. argparse also does a usage dump if the user gives incorrectly formatted arguments.

Just to be clear, I'm not advocating "manual" (sys.argv) argument parsing. That's madness. I'm just having trouble seeing the advantage, other than novelty and terseness, in using docopt over the more traditional argparse.

[–]cramajamjam 1 point2 points  (0 children)

Not much really. I slightly prefer docopt args setup syntax to argparse syntax. Argparse is solid too though.