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
Provenance
- Commit
5d85db9- Tree
6f37b6c- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
c8e6154
1 file changed+45 added−7 removed
modified:docs/why.rst+45 added-7 removed
63 unmodified lines64 Why not Docopt etc.?65 --------------------66 67 Docopt and many tools like it are cool in how they work but very few of68-these tools deal with nesting of commands. To the best of the developer's69-knowledge, click is the first Python library that tries to aim for70-composability of applications that goes beyond what the system itself71-supports.68+these tools deal with nesting of commands and composability in a way like69+click. To the best of the developer's knowledge, click is the first70+Python library that tries to aim for composability of applications that71+goes beyond what the system itself supports.72 73-For instance a click subcommand could accept all the arguments unparsed74-and then be parsed with docopt if that command would want to work that75-way.73+Docopt for instance acts by parsing your help pages and then parsing74+according do those rules. The side effect of this is that docopt is quite75+rigid in how it handles the command line interface. The upside of docopt76+is that it gives you strong control over your help page, the downside is77+that due to that it cannot rewrap your output for the current terminal78+width and it makes translations hard. On top of that docopt is restricted79+to basic parsing. It does not handle argument dispatching and callback80+invocation or types. This means there is a lot of code that needs to be81+written in addition to the basic help page to handle the parsing results.82 83+Most of all however it makes composability hard. While docopt does84+support dispatching to subcommands, it for instance does not directly85+support any kind of automatic subcommand enumeration based on what's86+available or it does not enforce subcommands to work in a consistent way.87+88+This is fine, but it's different from how Click wants to work. Click aims89+to support fully composable command line user interfaces by doing this:90+91+- 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.106+107+The aim of click is to make composable systems, whereas the aim of docopt108+is to build the most beautiful and hand-crafted command line interfaces.109+These two goals are conflicting with each other in subtle ways. Click110+actively prevents people from implementing certain patterns in order to111+achieve unified command line interfaces. You have very little input on112+reformatting your help pages for instance.113+114+115 Why Hardcoded Behaviors?116 ------------------------117 118 The other question is why click goes away from optparse and hardcodes14 unmodified lines