Skip to content
Myr

Updated notes on docopt

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent c8e6154 · Browse files · 1 file+45 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+45 added−7 removed

  • other:+45 added−7 removed

1 file+45 added−7 removed

modified:docs/why.rst+45 added-7 removed
63 unmodified lines
64Why not Docopt etc.?65--------------------6667Docopt and many tools like it are cool in how they work but very few of68these tools deal with nesting of commands. To the best of the developer's69knowledge, click is the first Python library that tries to aim for70composability of applications that goes beyond what the system itself71supports.68these tools deal with nesting of commands and composability in a way like69click. To the best of the developer's knowledge, click is the first70Python library that tries to aim for composability of applications that71goes beyond what the system itself supports.7273For instance a click subcommand could accept all the arguments unparsed74and then be parsed with docopt if that command would want to work that75way.73Docopt for instance acts by parsing your help pages and then parsing74according do those rules. The side effect of this is that docopt is quite75rigid in how it handles the command line interface. The upside of docopt76is that it gives you strong control over your help page, the downside is77that due to that it cannot rewrap your output for the current terminal78width and it makes translations hard. On top of that docopt is restricted79to basic parsing. It does not handle argument dispatching and callback80invocation or types. This means there is a lot of code that needs to be81written in addition to the basic help page to handle the parsing results.8283Most of all however it makes composability hard. While docopt does84support dispatching to subcommands, it for instance does not directly85support any kind of automatic subcommand enumeration based on what's86available or it does not enforce subcommands to work in a consistent way.8788This is fine, but it's different from how Click wants to work. Click aims89to support fully composable command line user interfaces by doing this:9091- click does not just parse, it also dispatches to the appropriate code92- click has a strong concept of an invocation context that allows93 subcommands to respond to data from the parent command.94- click has strong information available for all parameters and commands95 so that it can generate unified help pages for the full CLI and to96 assist the user in converting the input data as necessary.97- click has strong understanding of what types are and can give the user98 consistent error messages if something goes wrong. A subcommand99 written by a different developer will not suddenly die with a100 different error messsage because it's manually handled.101- click has enough meta information available for it's whole program102 that it can evolve over time to improve the user experience without103 forcing developers to adjust their programs. For instance if click104 decides to change how help pages are formatted, all click programs105 will automatically benefit from this.106107The aim of click is to make composable systems, whereas the aim of docopt108is to build the most beautiful and hand-crafted command line interfaces.109These two goals are conflicting with each other in subtle ways. Click110actively prevents people from implementing certain patterns in order to111achieve unified command line interfaces. You have very little input on112reformatting your help pages for instance.113114115Why Hardcoded Behaviors?116------------------------117118The other question is why click goes away from optparse and hardcodes
14 unmodified lines