Skip to content
Myr

Merge pull request #125 from iKevinY/doc-fixes

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

Documentation Fixes

authored by Armin Ronacher · committed by Armin Ronacher · parents 5bf07ba, 6358f9f · Browse files · 10 files+82 added−79 removed
This commit

State

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

Diff stats

10 files+82 added−79 removed

  • other:+82 added−79 removed

10 files+82 added−79 removed

modified:docs/advanced.rst+13 added-14 removed
2 unmodified lines
34.. currentmodule:: click56In addition to common functionality that is implemented in the library7itself, there are countless of patterns that can be implemented by extending8click. This page should give some inspiration of what can be9accomplished.7itself, there are countless patterns that can be implemented by extending8click. This page should give some insight into what can be accomplished.910.. _aliases:1112Command Aliases13---------------1415Many tools support aliases for commands. For instance, you can configure16``git`` to accept ``git ci`` as alias for ``git commit``. Other tools18also support auto discovery for aliases by automatically shortening them.17also support auto-discovery for aliases by automatically shortening them.1820Click does not support this out of the box but it's very easy to customize19Click does not support this out of the box, but it's very easy to customize20the :class:`Group` or any other :class:`MultiCommand` to provide this21functionality.2223As explained in :ref:`custom-multi-commands`, a multi command can provide
2 unmodified lines
26to override the latter as you generally don't want to enumerate the27aliases on the help page in order to avoid confusion.2829This following example implements a subclass of :class:`Group` that31accepts a prefix for a command. If there were a command called32``push``, it would accept ``pus`` as an alias if it was unique:30accepts a prefix for a command. If there were a command called ``push``,31it would accept ``pus`` as an alias (so long as it was unique):3233.. click:example::3435 class AliasedGroup(click.Group):
30 unmodified lines
66-------------------6768.. versionadded:: 2.06971Starting with click 2.0 it's possible to provide a function that is used72for normalizing tokens. Tokens are option names, choice values or command73values. This can be used to implement case insensitive options for70Starting with click 2.0, it's possible to provide a function that is used71for normalizing tokens. Tokens are option names, choice values, or command72values. This can be used to implement case insensitive options, for73instance.7476In order to use this feature you need to implement a function that77performs the normalization of the token. For instance you could have a78function that converts the token to lowercase. Example:75In order to use this feature, the context needs to be passed a function that76performs the normalization of the token. For instance, you could have a77function that converts the token to lowercase:7879.. click:example::8081 CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())
2 unmodified lines
84 @click.option('--name', default='Pete')85 def cli(name):86 click.echo('Name: %s' % name)8789And how it works on the UI:88And how it works on the command line:8990.. click:run::9192 invoke(cli, prog_name='cli', args=['--NAME=Pete'])
98 unmodified lines
modified:docs/arguments.rst+7 added-7 removed
1 unmodified line
2=========34.. currentmodule:: click56Arguments work similarly to options, but are positional. They also only6Arguments work similarly to options but are positional. They also only7support a subset of the features of options due to their syntactical nature.8Click will also not attempt to document arguments for you and wants you to9document them manually in order to avoid ugly help pages.10
54 unmodified lines
65this, see the next sections.6667.. admonition:: Note on Non-Empty Variadic Arguments6869 If you come from ``argparse`` you might be missing support for setting69 If you come from ``argparse``, you might be missing support for setting70 ``nargs`` to ``+`` to indicate that at least one argument is required.7172 This is supported by setting ``required=True``. However, this should73 not be used if you can avoid it as we believe scripts should gracefully
41 unmodified lines
115116File Path Arguments117-------------------118119In the previous example the files were opened immediately. But what if120we just want the filename? The naive way is to use the default string119In the previous example, the files were opened immediately. But what if120we just want the filename? The naïve way is to use the default string121argument type. However, remember that click is Unicode-based, so the string122will always be a Unicode value. Unfortunately, filenames can be Unicode or123bytes depending on which operating system is being used. As such, the type124is insufficient.125126Instead, you should be using the :class:`Path` type, which handles this127complexity for you. Not only will it return either bytes or Unicode126Instead, you should be using the :class:`Path` type, which automatically127handles this ambiguity. Not only will it return either bytes or Unicode128depending on what makes more sense, but it will also be able to do some129basic checks for you such as existence checks.130131Example:
81 unmodified lines
213Generally, this feature is not recommended because it can cause the user214a lot of confusion.215216Argument-Like Options217------------------------------217---------------------218219Sometimes, you want to process arguments that look like options. For220instance, imagine you have a file named ``-foo.txt``. If you pass this as221an argument in this manner, click will treat it as an option.
21 unmodified lines
modified:docs/documentation.rst+11 added-10 removed
3 unmodified lines
4.. currentmodule:: click56Click makes it very easy to document your command line tools. First of7all, it automatically generates help pages for you. While these are8currently not customizable in layout, all of the text can be changed.8currently not customizable in terms of their layout, all of the text9can be changed.1011Help Texts12----------1313Commands and options accept help arguments. In the case of commands, the doc14string of the function is automatically used if provided.14Commands and options accept help arguments. In the case of commands, the15docstring of the function is automatically used if provided.1617Simple example:1819.. click:example::
19 unmodified lines
3940Preventing Rewrapping41---------------------4242The default behavior of click is to rewrap text to work correctly for the43width of the terminal. In some circumstances, this can become a problem.44The main issue is showing code examples where newlines are significant.43The default behavior of click is to rewrap text based on the width of the44terminal. In some circumstances, this can become a problem. The main issue45is when showing code examples, where newlines are significant.4647Rewrapping can be disabled on a per-paragraph basis by adding a line with48solely the ``\b`` escape marker in it. This line will be removed from the49help text and rewrapping will be disabled.
85 unmodified lines
135----------------------------136137.. versionadded:: 2.0138138The help parameter is very special in how it's implemented in click.139The help parameter is implemented in click in a very special manner.140Unlike regular parameters it's automatically added by click for any141command and it performs automatic conflict resolution. By default it's141called ``--help`` but this can be changed. If a command itself implements142a parameter with the same name the default help parameter stops accepting142called ``--help``, but this can be changed. If a command itself implements143a parameter with the same name, the default help parameter stops accepting144it. There is a context setting that can be used to override the names of145the help parameters called :attr:`~Context.help_option_names`.146147This example changes the default parameters to ``-h`` and ``--help``147instad of just ``--help``:148instead of just ``--help``:149150.. click:example::151152 CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
10 unmodified lines
modified:docs/index.rst+14 added-13 removed
1Welcome to the Click Documentation2==================================34Click is a Python package for creating beautiful command line interfaces5in a composable way with as little amount of code as necessary. It's the6"Command Line Interface Creation Kit". It's highly configurable but comes7with good defaults out of the box.5in a composable way with as little code as necessary. It's the "Command6Line Interface Creation Kit". It's highly configurable but comes with7sensible defaults out of the box.89It aims at making writing command line tools fun and quick without causing10user frustration at not being able to implement an intended CLI API.9It aims to make the process of writing command line tools quick and fun10while also preventing any frustration caused by the inability to implement11an intended CLI API.1213Click in three points:1415- arbitrary nesting of commands16- automatic help page generation17- supports lazy loading of subcommands at runtime1818What does it look like? A simple example can be this:19What does it look like? Here is an example of a simple click program:2021.. click:example::2223 import click
9 unmodified lines
3334 if __name__ == '__main__':35 hello()3636And what it looks like:37And what it looks like when run:3839.. click:run::4041 invoke(hello, ['--count=3'], input='John\n')4242And it gives you nicely formatted help pages:43It automatically generates nicely formatted help pages:4445.. click:run::4647 invoke(hello, ['--help'])
4 unmodified lines
5253Documentation Contents54----------------------5555This part of the documentation guides you through all the usage patterns56of the library.56This part of the documentation guides you through all of the library's57usage patterns.5859.. toctree::60 :maxdepth: 261
15 unmodified lines
7778API Reference79-------------8080If you are looking for information on a specific function, class or81If you are looking for information on a specific function, class, or82method, this part of the documentation is for you.8384.. toctree::85 :maxdepth: 28687 api8888Other Documents89---------------89Miscellaneous Pages90-------------------9192.. toctree::93 :maxdepth: 294
3 unmodified lines
modified:docs/prompts.rst+6 added-5 removed
14 unmodified lines
15--------------1617Option prompts are integrated into the option interface. See18:ref:`option-prompting` for more information. Internally, it19automatically calls into :func:`prompt` or :func:`confirm` as necessary.19automatically calls either :func:`prompt` or :func:`confirm` as necessary.2021Input Prompts22-------------2324To manually ask for user input, you can use the :func:`prompt` function.25By default, it accepts any Unicode string, but you can ask for any other26type. For instance you can ask for a valid integer::26type. For instance, you can ask for a valid integer::2728 value = click.prompt('Please enter a valid integer', type=int)2930The type is also automatically detected if a default is provided. For31instance, the following will only accept floats::30Additionally, the type will be determined automatically if a default value is31provided. For instance, the following will only accept floats::3233 value = click.prompt('Please enter a number', default=42.0)3435Confirmation Prompts
5 unmodified lines
4142 if click.confirm('Do you want to continue?'):43 click.echo('Well done!')4445There is also the option to make it automatically abort the execution::45There is also the option to make the function automatically abort the46execution of the program if it does not return ``True``::4748 click.confirm('Do you want to continue?', abort=True)
modified:docs/python3.rst+8 added-8 removed
1 unmodified line
2================34.. currentmodule:: click56Click supports Python 3 but like all other command line utility libraries,6Click supports Python 3, but like all other command line utility libraries,7it suffers from the Unicode text model in Python 3. All examples in the8documentation were written so that they run on both Python 2.x and8documentation were written so that they could run on both Python 2.x and9Python 3.3 or higher.1011At the moment the strong recommendation is to use Python 2 for these11At the moment, it is strongly recommended is to use Python 2 for click12utilities unless Python 3 is a hard requirement.1314.. _python3-limitations:15
41 unmodified lines
5758Click attempts to minimize the differences between Python 2 and Python 359by following the best practices for both languages.6061in Python 2, the following is true:61In Python 2, the following is true:6263* ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` are opened in binary64 mode, but under some circumstances they support Unicode output. Click65 attempts to not subvert this but provides support for forcing streams
5 unmodified lines
71* When dealing with files, click will never go through the Unicode APIs72 and will instead use the operating system's byte APIs to open the73 files.7475in Python 3, the following is true:75In Python 3, the following is true:7677* ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are by default78 text-based. When click needs a binary stream, it attempts to discover79 the underlying binary stream. See :ref:`python3-limitations` for how
46 unmodified lines
126You are dealing with an environment where Python 3 thinks you are127restricted to ASCII data. The solution to these problems is different128depending on which locale your computer is running in.129130For instance if you have a German Linux machine you can fix the problem130For instance, if you have a German Linux machine, you can fix the problem131by exporting the locale to ``de_DE.utf-8``::132133 export LC_ALL=de_DE.utf-8134 export LANG=de_DE.utf-8135136If you are on a US machine, ``en_EN.utf-8`` is the encoding of choice. On137some newer Linux systems you can also try ``C.UTF-8`` as locale::137some newer Linux systems, you could also try ``C.UTF-8`` as the locale::138139 export LC_ALL=C.UTF-8140 export LANG=C.UTF-8141142You need to do this before you invoke your Python script. If you are143curious about the reasons for this you can join the discussions in the143curious about the reasons for this, you can join the discussions in the144Python 3 bug tracker:145146* `ASCII is a bad filesystem default encoding147 <http://bugs.python.org/issue13643#msg149941>`_
7 unmodified lines
modified:docs/quickstart.rst+3 added-3 removed
15 unmodified lines
1617* `Building Command Line Applications with Click18 <https://www.youtube.com/watch?v=kNke39OZ2k0>`_1920Examples of Click applications can be found in the documentation as well21as in the github repository together with readme files:20Examples of click applications can be found in the documentation as well21as in the GitHub repository together with readme files:2223* ``inout``: `File input and output24 <https://github.com/mitsuhiko/click/tree/master/examples/inout>`_25* ``naval``: `Port of docopt naval example26 <https://github.com/mitsuhiko/click/tree/master/examples/naval>`_27* ``aliases``: `Command alias example28 <https://github.com/mitsuhiko/click/tree/master/examples/aliases>`_29* ``repo``: `Git/hg like command line interface29* ``repo``: `Git-/Mercurial-like command line interface30 <https://github.com/mitsuhiko/click/tree/master/examples/repo>`_31* ``complex``: `Complex example with plugin loading32 <https://github.com/mitsuhiko/click/tree/master/examples/complex>`_33* ``validation``: `Custom parameter validation example
130 unmodified lines
modified:docs/setuptools.rst+2 added-2 removed
65 unmodified lines
6667Testing The Script68------------------6970To test the script you can make a new virtualenv and then install your70To test the script, you can make a new virtualenv and then install your71package::7273 $ virtualenv venv74 $ . venv/bin/activate75 $ pip install --editable .7677Afterwards your command should be available:77Afterwards, your command should be available:7879.. click:run::8081 invoke(cli, prog_name='yourscript', prog_prefix='')
modified:docs/why.rst+11 added-11 removed
27 unmodified lines
28nesting of commands by design and has some deficiencies when it comes to29POSIX compliant argument handling.3031Click is designed to be fun to work with and at the same time not stand in32your way. It's not overly flexible at the same time either. Currently33for instance it does not allow you to customize the help pages too much.34This is intentional because click is designed to allow you to nest command35line utilities. The idea is that you can have a system that works36together with another system by tacking two click instances together and37they will continue working as they should.32your way. It's not overly flexible either. Currently, for instance, it33does not allow you to customize the help pages too much. This is intentional34because click is designed to allow you to nest command line utilities. The35idea is that you can have a system that works together with another system by36tacking two click instances together and they will continue working as they37should.3839Too much customizability would break this promise.4041Click was written to support the `Flask <http://flask.pocoo.org/>`_42microframework ecosystem because no tool could provide it with the43functionality it needed.4445To get an understanding of what click is all about I strongly recommend45To get an understanding of what click is all about, I strongly recommend46looking at the :ref:`complex-guide` chapter to see what it's useful for.4748Why not Argparse?49-----------------
16 unmodified lines
6667Why not Docopt etc.?68--------------------6970Docopt and many tools like it are cool in how they work but very few of70Docopt and many tools like it are cool in how they work, but very few of71these tools deal with nesting of commands and composability in a way like72click. To the best of the developer's knowledge, click is the first73Python library that tries to aim for composability of applications that74goes beyond what the system itself supports.73Python library that aims to create a level of composability of applications74that goes beyond what the system itself supports.7576Docopt for instance acts by parsing your help pages and then parsing76Docopt, for instance, acts by parsing your help pages and then parsing77according to those rules. The side effect of this is that docopt is quite78rigid in how it handles the command line interface. The upside of docopt79is that it gives you strong control over your help page; the downside is80that due to this it cannot rewrap your output for the current terminal
72 unmodified lines
modified:README+7 added-6 removed
1$ click_23 Click is a Python package for creating beautiful command line interfaces4 in a composable way with as little amount of code as necessary. It's the5 "Command Line Interface Creation Kit". It's highly configurable but comes6 with good defaults out of the box.4 in a composable way with as little code as necessary. It's the "Command5 Line Interface Creation Kit". It's highly configurable but comes with6 sensible defaults out of the box.78 It aims to make writing command line tools quick and fun without causing9 user frustration from the inability to implement a desired CLI API.8 It aims to make the process of writing command line tools quick and fun9 while also preventing any frustration caused by the inability to implement10 an intended CLI API.1112 Click in three points:1314 - arbitrary nesting of commands
1 unmodified line
16 - supports lazy loading of subcommands at runtime1718 Read the docs at http://click.pocoo.org/1919 This library is work in progress. Please give feedback!20 This library is a work in progress. Please give feedback!