Increase readibility of 'why' page in docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Richard · committed by Richard Hayes · parent 224b4b2 · Browse files · 1 file·+27 added−31 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+27 added−31 removed
- other:+27 added−31 removed
Provenance
- Commit
df36931- Tree
40fde43- Author
Richard <rhshadowgreen@gmail.com>- Committer
Richard Hayes <rhshadowgreen@gmail.com>- Parent
224b4b2
1 file changed+27 added−31 removed
modified:docs/why.rst+27 added-31 removed
8 unmodified lines9 10 * is lazily composable without restrictions11 * supports implementation of Unix/POSIX command line conventions12 * supports loading values from environment variables out of the box13-* supports for prompting of custom values13+* support for prompting of custom values14 * is fully nestable and composable15 * works the same in Python 2 and 316 * supports file handling out of the box17 * comes with useful common helpers (getting terminal dimensions,18 ANSI colors, fetching direct keyboard input, screen clearing,19 finding config paths, launching apps and editors, etc.)20 21-There are many alternatives to Click and you can have a look at them if22-you enjoy them better. The obvious ones are ``optparse`` and ``argparse``23-from the standard library.21+There are many alternatives to Click; the obvious ones are ``optparse``22+and ``argparse`` from the standard library. Have a look to see if something23+else resonates with you.24 25 Click actually implements its own parsing of arguments and does not use26 ``optparse`` or ``argparse`` following the ``optparse`` parsing behavior.27 The reason it's not based on ``argparse`` is that ``argparse`` does not28 allow proper nesting of commands by design and has some deficiencies when29 it comes to POSIX compliant argument handling.30 31-Click is designed to be fun to work with and at the same time not stand in32-your way. It's not overly flexible either. Currently, for instance, it33-does not allow you to customize the help pages too much. This is intentional34-because Click is designed to allow you to nest command line utilities. The35-idea is that you can have a system that works together with another system by36-tacking two Click instances together and they will continue working as they37-should.31+Click is designed to be fun and customizable but not overly flexible.32+For instance, the customizability of help pages is constrained. This33+constraint is intentional because Click promises multiple Click instances34+will continue to function as intended when strung together.35 36 Too much customizability would break this promise.37 38 Click was written to support the `Flask <http://flask.pocoo.org/>`_39 microframework ecosystem because no tool could provide it with the40 functionality it needed.41 42 To get an understanding of what Click is all about, I strongly recommend46-looking at the :ref:`complex-guide` chapter to see what it's useful for.43+looking at the :ref:`complex-guide` chapter.44 45 Why not Argparse?46 -----------------47 51-Click is internally based on optparse instead of argparse. This however48+Click is internally based on ``optparse`` instead of ``argparse``. This49 is an implementation detail that a user does not have to be concerned53-with. The reason however Click is not using argparse is that it has some50+with. The reason Click is not using argparse is it has some51 problematic behaviors that make handling arbitrary command line interfaces52 hard:53 54 * argparse has built-in magic behavior to guess if something is an58- argument or an option. This becomes a problem when dealing with59- incomplete command lines as it's not possible to know without having a60- full understanding of the command line how the parser is going to61- behave. This goes against Click's ambitions of dispatching to62- subparsers.55+ argument or an option. This behavior becomes a problem when dealing with56+ incomplete command lines; the parsers behaviour becomes unpredictable57+ without full knowledge of a command line. This goes against Click's58+ ambitions of dispatching to subparsers.59 * argparse currently does not support disabling of interspersed64- arguments. Without this feature it's not possible to safely implement60+ arguments. Without this feature, it's not possible to safely implement61 Click's nested parsing nature.62 63 Why not Docopt etc.?64 --------------------65 70-Docopt and many tools like it are cool in how they work, but very few of66+Docopt, and many tools like, it are cool in how they work, but very few of67 these tools deal with nesting of commands and composability in a way like68 Click. To the best of the developer's knowledge, Click is the first69 Python library that aims to create a level of composability of applications70 that goes beyond what the system itself supports.2 unmodified lines73 according to those rules. The side effect of this is that docopt is quite74 rigid in how it handles the command line interface. The upside of docopt75 is that it gives you strong control over your help page; the downside is76 that due to this it cannot rewrap your output for the current terminal81-width and it makes translations hard. On top of that docopt is restricted77+width, and it makes translations hard. On top of that, docopt is restricted78 to basic parsing. It does not handle argument dispatching and callback79 invocation or types. This means there is a lot of code that needs to be80 written in addition to the basic help page to handle the parsing results.81 82 Most of all, however, it makes composability hard. While docopt does87-support dispatching to subcommands, it for instance does not directly83+support dispatching to subcommands, it, for instance, does not directly84 support any kind of automatic subcommand enumeration based on what's85 available or it does not enforce subcommands to work in a consistent way.86 87 This is fine, but it's different from how Click wants to work. Click aims2 unmodified lines90 91 - Click does not just parse, it also dispatches to the appropriate code.92 - Click has a strong concept of an invocation context that allows93 subcommands to respond to data from the parent command.98-- Click has strong information available for all parameters and commands99- so that it can generate unified help pages for the full CLI and to94+- Click has strong information available for all parameters and commands,95+ so it can generate unified help pages for the full CLI and96 assist the user in converting the input data as necessary.101-- Click has a strong understanding of what types are and can give the user97+- Click has a strong understanding of what types are, and it 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 message because it's manually handled.101 - Click has enough meta information available for its whole program106- that it can evolve over time to improve the user experience without102+ to evolve over time and 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 111-The aim of Click is to make composable systems, whereas the aim of docopt107+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 conflict with one another in subtle ways. Click110 actively prevents people from implementing certain patterns in order to115-achieve unified command line interfaces. You have very little input on116-reformatting your help pages for instance.111+achieve unified command line interfaces. For instance, as a developer, you112+are given very little choice in formatting your help pages.113 114 115 Why Hardcoded Behaviors?116 ------------------------22 unmodified lines139 even optparse and argparse support automatic expansion of long arguments.140 The reason for this is that it's a liability for backwards compatibility.141 If people start relying on automatically modified parameters and someone142 adds a new parameter in the future, the script might stop working. These147-kinds of problems are hard to find so Click does not attempt to be magical143+kinds of problems are hard to find, so Click does not attempt to be magical144 about this.145 146 This sort of behavior however can be implemented on a higher level to147 support things such as explicit aliases. For more information see1 unmodified line