change extension to .md
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by denuoweb · committed by denuoweb · parent 2d610e3 · Browse files · 2 files·+146 added−146 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+146 added−146 removed
- other:+146 added−146 removed
Provenance
- Commit
79ba04f- Tree
6036c24- Author
denuoweb <jaron@rosenau.info>- Committer
denuoweb <jaron@rosenau.info>- Parent
2d610e3
2 files changed+146 added−146 removed
added:docs/why.md+146 added
1+Why Click?2+==========3+4+There are so many libraries out there for writing command line utilities;5+why does Click exist?6+7+This question is easy to answer: because there is not a single command8+line utility for Python out there which ticks the following boxes:9+10+* Is lazily composable without restrictions.11+* Supports implementation of Unix/POSIX command line conventions.12+* Supports loading values from environment variables out of the box.13+* Support for prompting of custom values.14+* Is fully nestable and composable.15+* Supports file handling out of the box.16+* Comes with useful common helpers (getting terminal dimensions,17+ ANSI colors, fetching direct keyboard input, screen clearing,18+ finding config paths, launching apps and editors, etc.).19+20+There are many alternatives to Click; the obvious ones are ``optparse``21+and ``argparse`` from the standard library. Have a look to see if something22+else resonates with you.23+24+Click actually implements its own parsing of arguments and does not use25+``optparse`` or ``argparse`` following the ``optparse`` parsing behavior.26+The reason it's not based on ``argparse`` is that ``argparse`` does not27+allow proper nesting of commands by design and has some deficiencies when28+it comes to POSIX compliant argument handling.29+30+Click is designed to be fun and customizable but not overly flexible.31+For instance, the customizability of help pages is constrained. This32+constraint is intentional because Click promises multiple Click instances33+will continue to function as intended when strung together.34+35+Too much customizability would break this promise.36+37+Click was written to support the `Flask <https://palletsprojects.com/p/flask/>`_38+microframework ecosystem because no tool could provide it with the39+functionality it needed.40+41+To get an understanding of what Click is all about, I strongly recommend42+looking at the :ref:`complex-guide` chapter.43+44+Why not Argparse?45+-----------------46+47+Click is internally based on ``optparse`` instead of ``argparse``. This48+is an implementation detail that a user does not have to be concerned49+with. Click is not based on ``argparse`` because it has some behaviors that50+make handling arbitrary command line interfaces hard:51+52+* ``argparse`` has built-in behavior to guess if something is an53+ argument or an option. This becomes a problem when dealing with54+ incomplete command lines; the behaviour becomes unpredictable55+ without full knowledge of a command line. This goes against Click's56+ ambitions of dispatching to subparsers.57+* ``argparse`` does not support disabling interspersed arguments. Without58+ this feature, it's not possible to safely implement Click's nested59+ parsing.60+61+Why not Docopt etc.?62+--------------------63+64+Docopt, and many tools like it, are cool in how they work, but very few of65+these tools deal with nesting of commands and composability in a way like66+Click. To the best of the developer's knowledge, Click is the first67+Python library that aims to create a level of composability of applications68+that goes beyond what the system itself supports.69+70+Docopt, for instance, acts by parsing your help pages and then parsing71+according to those rules. The side effect of this is that docopt is quite72+rigid in how it handles the command line interface. The upside of docopt73+is that it gives you strong control over your help page; the downside is74+that due to this it cannot rewrap your output for the current terminal75+width, and it makes translations hard. On top of that, docopt is restricted76+to basic parsing. It does not handle argument dispatching and callback77+invocation or types. This means there is a lot of code that needs to be78+written in addition to the basic help page to handle the parsing results.79+80+Most of all, however, it makes composability hard. While docopt does81+support dispatching to subcommands, it, for instance, does not directly82+support any kind of automatic subcommand enumeration based on what's83+available or it does not enforce subcommands to work in a consistent way.84+85+This is fine, but it's different from how Click wants to work. Click aims86+to support fully composable command line user interfaces by doing the87+following:88+89+- Click does not just parse, it also dispatches to the appropriate code.90+- Click has a strong concept of an invocation context that allows91+ subcommands to respond to data from the parent command.92+- Click has strong information available for all parameters and commands,93+ so it can generate unified help pages for the full CLI and94+ assist the user in converting the input data as necessary.95+- Click has a strong understanding of what types are, and it can give the user96+ consistent error messages if something goes wrong. A subcommand97+ written by a different developer will not suddenly die with a98+ different error message because it's manually handled.99+- Click has enough meta information available for its whole program100+ to evolve over time and improve the user experience without101+ forcing developers to adjust their programs. For instance, if Click102+ decides to change how help pages are formatted, all Click programs103+ will automatically benefit from this.104+105+The aim of Click is to make composable systems. Whereas, the aim of docopt106+is to build the most beautiful and hand-crafted command line interfaces.107+These two goals conflict with one another in subtle ways. Click108+actively prevents people from implementing certain patterns in order to109+achieve unified command line interfaces. For instance, as a developer, you110+are given very little choice in formatting your help pages.111+112+113+Why Hardcoded Behaviors?114+------------------------115+116+The other question is why Click goes away from optparse and hardcodes117+certain behaviors instead of staying configurable. There are multiple118+reasons for this. The biggest one is that too much configurability makes119+it hard to achieve a consistent command line experience.120+121+The best example for this is optparse's ``callback`` functionality for122+accepting an arbitrary number of arguments. Due to syntactical ambiguities123+on the command line, there is no way to implement fully variadic arguments.124+There are always tradeoffs that need to be made and in case of125+``argparse`` these tradeoffs have been critical enough, that a system like126+Click cannot even be implemented on top of it.127+128+In this particular case, Click attempts to stay with a handful of accepted129+paradigms for building command line interfaces that can be well documented130+and tested.131+132+133+Why No Auto Correction?134+-----------------------135+136+The question came up why Click does not auto correct parameters given that137+even optparse and ``argparse`` support automatic expansion of long arguments.138+The reason for this is that it's a liability for backwards compatibility.139+If people start relying on automatically modified parameters and someone140+adds a new parameter in the future, the script might stop working. These141+kinds of problems are hard to find, so Click does not attempt to be magical142+about this.143+144+This sort of behavior however can be implemented on a higher level to145+support things such as explicit aliases. For more information see146+:ref:`aliases`.deleted:docs/why.rst-146 removed
1-Why Click?2-==========3-4-There are so many libraries out there for writing command line utilities;5-why does Click exist?6-7-This question is easy to answer: because there is not a single command8-line utility for Python out there which ticks the following boxes:9-10-* Is lazily composable without restrictions.11-* Supports implementation of Unix/POSIX command line conventions.12-* Supports loading values from environment variables out of the box.13-* Support for prompting of custom values.14-* Is fully nestable and composable.15-* Supports file handling out of the box.16-* Comes with useful common helpers (getting terminal dimensions,17- ANSI colors, fetching direct keyboard input, screen clearing,18- finding config paths, launching apps and editors, etc.).19-20-There are many alternatives to Click; the obvious ones are ``optparse``21-and ``argparse`` from the standard library. Have a look to see if something22-else resonates with you.23-24-Click actually implements its own parsing of arguments and does not use25-``optparse`` or ``argparse`` following the ``optparse`` parsing behavior.26-The reason it's not based on ``argparse`` is that ``argparse`` does not27-allow proper nesting of commands by design and has some deficiencies when28-it comes to POSIX compliant argument handling.29-30-Click is designed to be fun and customizable but not overly flexible.31-For instance, the customizability of help pages is constrained. This32-constraint is intentional because Click promises multiple Click instances33-will continue to function as intended when strung together.34-35-Too much customizability would break this promise.36-37-Click was written to support the `Flask <https://palletsprojects.com/p/flask/>`_38-microframework ecosystem because no tool could provide it with the39-functionality it needed.40-41-To get an understanding of what Click is all about, I strongly recommend42-looking at the :ref:`complex-guide` chapter.43-44-Why not Argparse?45------------------46-47-Click is internally based on ``optparse`` instead of ``argparse``. This48-is an implementation detail that a user does not have to be concerned49-with. Click is not based on ``argparse`` because it has some behaviors that50-make handling arbitrary command line interfaces hard:51-52-* ``argparse`` has built-in behavior to guess if something is an53- argument or an option. This becomes a problem when dealing with54- incomplete command lines; the behaviour becomes unpredictable55- without full knowledge of a command line. This goes against Click's56- ambitions of dispatching to subparsers.57-* ``argparse`` does not support disabling interspersed arguments. Without58- this feature, it's not possible to safely implement Click's nested59- parsing.60-61-Why not Docopt etc.?62---------------------63-64-Docopt, and many tools like it, are cool in how they work, but very few of65-these tools deal with nesting of commands and composability in a way like66-Click. To the best of the developer's knowledge, Click is the first67-Python library that aims to create a level of composability of applications68-that goes beyond what the system itself supports.69-70-Docopt, for instance, acts by parsing your help pages and then parsing71-according to those rules. The side effect of this is that docopt is quite72-rigid in how it handles the command line interface. The upside of docopt73-is that it gives you strong control over your help page; the downside is74-that due to this it cannot rewrap your output for the current terminal75-width, and it makes translations hard. On top of that, docopt is restricted76-to basic parsing. It does not handle argument dispatching and callback77-invocation or types. This means there is a lot of code that needs to be78-written in addition to the basic help page to handle the parsing results.79-80-Most of all, however, it makes composability hard. While docopt does81-support dispatching to subcommands, it, for instance, does not directly82-support any kind of automatic subcommand enumeration based on what's83-available or it does not enforce subcommands to work in a consistent way.84-85-This is fine, but it's different from how Click wants to work. Click aims86-to support fully composable command line user interfaces by doing the87-following:88-89-- Click does not just parse, it also dispatches to the appropriate code.90-- Click has a strong concept of an invocation context that allows91- subcommands to respond to data from the parent command.92-- Click has strong information available for all parameters and commands,93- so it can generate unified help pages for the full CLI and94- assist the user in converting the input data as necessary.95-- Click has a strong understanding of what types are, and it can give the user96- consistent error messages if something goes wrong. A subcommand97- written by a different developer will not suddenly die with a98- different error message because it's manually handled.99-- Click has enough meta information available for its whole program100- to evolve over time and improve the user experience without101- forcing developers to adjust their programs. For instance, if Click102- decides to change how help pages are formatted, all Click programs103- will automatically benefit from this.104-105-The aim of Click is to make composable systems. Whereas, the aim of docopt106-is to build the most beautiful and hand-crafted command line interfaces.107-These two goals conflict with one another in subtle ways. Click108-actively prevents people from implementing certain patterns in order to109-achieve unified command line interfaces. For instance, as a developer, you110-are given very little choice in formatting your help pages.111-112-113-Why Hardcoded Behaviors?114-------------------------115-116-The other question is why Click goes away from optparse and hardcodes117-certain behaviors instead of staying configurable. There are multiple118-reasons for this. The biggest one is that too much configurability makes119-it hard to achieve a consistent command line experience.120-121-The best example for this is optparse's ``callback`` functionality for122-accepting an arbitrary number of arguments. Due to syntactical ambiguities123-on the command line, there is no way to implement fully variadic arguments.124-There are always tradeoffs that need to be made and in case of125-``argparse`` these tradeoffs have been critical enough, that a system like126-Click cannot even be implemented on top of it.127-128-In this particular case, Click attempts to stay with a handful of accepted129-paradigms for building command line interfaces that can be well documented130-and tested.131-132-133-Why No Auto Correction?134------------------------135-136-The question came up why Click does not auto correct parameters given that137-even optparse and ``argparse`` support automatic expansion of long arguments.138-The reason for this is that it's a liability for backwards compatibility.139-If people start relying on automatically modified parameters and someone140-adds a new parameter in the future, the script might stop working. These141-kinds of problems are hard to find, so Click does not attempt to be magical142-about this.143-144-This sort of behavior however can be implemented on a higher level to145-support things such as explicit aliases. For more information see146-:ref:`aliases`.