convert from reST to MyST
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by denuoweb · committed by denuoweb · parent 11384eb · Browse files · 1 file·+87 added−97 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+87 added−97 removed
- other:+87 added−97 removed
Provenance
- Commit
38d9d60- Tree
eb3a476- Author
denuoweb <jaron@rosenau.info>- Committer
denuoweb <jaron@rosenau.info>- Parent
11384eb
1 file changed+87 added−97 removed
modified:docs/quickstart.md+87 added-97 removed
1-Quickstart2-==========1+# Quickstart2 4-.. currentmodule:: click3+```{currentmodule} click4+```5 6-Install7-----------------------8-Install from PyPI::6+## Install7 10- pip install click8+Install from PyPI:9 12-Installing into a virtual environment is highly recommended. We suggest :ref:`virtualenv-heading`.10+```console11+pip install click12+```13 14-Examples15------------------------14+Installing into a virtual environment is highly recommended. We suggest {ref}`virtualenv-heading`.15 17-Some standalone examples of Click applications are packaged with Click. They are available in the `examples folder <https://github.com/pallets/click/tree/main/examples>`_ of the repo.16+## Examples17 19-* `inout <https://github.com/pallets/click/tree/main/examples/inout>`_ : A very simple example of an application that can read from files and write to files and also accept input from stdin or write to stdout.20-* `validation <https://github.com/pallets/click/tree/main/examples/validation>`_ : A simple example of an application that performs custom validation of parameters in different ways.21-* `naval <https://github.com/pallets/click/tree/main/examples/naval>`_ : Port of the `docopt <http://docopt.org/>`_ naval example.22-* `colors <https://github.com/pallets/click/tree/main/examples/colors>`_ : A simple example that colorizes text. Uses colorama on Windows.23-* `aliases <https://github.com/pallets/click/tree/main/examples/aliases>`_ : An advanced example that implements :ref:`aliases`.24-* `imagepipe <https://github.com/pallets/click/tree/main/examples/imagepipe>`_ : A complex example that implements some :ref:`command-pipelines` . It chains together image processing instructions. Requires pillow.25-* `repo <https://github.com/pallets/click/tree/main/examples/repo>`_ : An advanced example that implements a Git-/Mercurial-like command line interface.26-* `complex <https://github.com/pallets/click/tree/main/examples/complex>`_ : A very advanced example that implements loading subcommands dynamically from a plugin folder.27-* `termui <https://github.com/pallets/click/tree/main/examples/termui>`_ : A simple example that showcases terminal UI helpers provided by click.18+Some standalone examples of Click applications are packaged with Click. They are available in the19+[examples folder](https://github.com/pallets/click/tree/main/examples) of the repo.20 29-Basic Concepts - Creating a Command30------------------------------------21+- [inout](https://github.com/pallets/click/tree/main/examples/inout) : A very simple example of an application that can22+ read from files and write to files and also accept input from stdin or write to stdout.23+- [validation](https://github.com/pallets/click/tree/main/examples/validation) : A simple example of an application that24+ performs custom validation of parameters in different ways.25+- [naval](https://github.com/pallets/click/tree/main/examples/naval) : Port of the [docopt](http://docopt.org/) naval26+ example.27+- [colors](https://github.com/pallets/click/tree/main/examples/colors) : A simple example that colorizes text. Uses28+ colorama on Windows.29+- [aliases](https://github.com/pallets/click/tree/main/examples/aliases) : An advanced example that implements30+ {ref}`aliases`.31+- [imagepipe](https://github.com/pallets/click/tree/main/examples/imagepipe) : A complex example that implements some32+ {ref}`command-pipelines` . It chains together image processing instructions. Requires pillow.33+- [repo](https://github.com/pallets/click/tree/main/examples/repo) : An advanced example that implements a34+ Git-/Mercurial-like command line interface.35+- [complex](https://github.com/pallets/click/tree/main/examples/complex) : A very advanced example that implements36+ loading subcommands dynamically from a plugin folder.37+- [termui](https://github.com/pallets/click/tree/main/examples/termui) : A simple example that showcases terminal UI38+ helpers provided by click.39 32-Click is based on declaring commands through decorators. Internally, there33-is a non-decorator interface for advanced use cases, but it's discouraged34-for high-level usage.40+## Basic Concepts - Creating a Command41 36-A function becomes a Click command line tool by decorating it through37-:func:`click.command`. At its simplest, just decorating a function38-with this decorator will make it into a callable script:42+Click is based on declaring commands through decorators. Internally, there is a non-decorator interface for advanced use43+cases, but it's discouraged for high-level usage.44 40-.. click:example::45+A function becomes a Click command line tool by decorating it through {func}`click.command`. At its simplest, just46+decorating a function with this decorator will make it into a callable script:47 48+49+```{eval-rst}50+.. click:example::51 import click52 53 @click.command()54 def hello():55 click.echo('Hello World!')56 48-What's happening is that the decorator converts the function into a49-:class:`Command` which then can be invoked::57+What's happening is that the decorator converts the function into a :class:`Command` which then can be invoked:58 59+.. click:example::60 if __name__ == '__main__':61 hello()62 63 And what it looks like:64 65 .. click:run::57-66 invoke(hello, args=[], prog_name='python hello.py')67 68 And the corresponding help page:69 70 .. click:run::63-71 invoke(hello, args=['--help'], prog_name='python hello.py')72+```73 66-Echoing67--------74+## Echoing75 69-Why does this example use :func:`echo` instead of the regular70-:func:`print` function? The answer to this question is that Click71-attempts to support different environments consistently and to be very72-robust even when the environment is misconfigured. Click wants to be73-functional at least on a basic level even if everything is completely74-broken.76+Why does this example use {func}`echo` instead of the regular {func}`print` function? The answer to this question is77+that Click attempts to support different environments consistently and to be very robust even when the environment is78+misconfigured. Click wants to be functional at least on a basic level even if everything is completely broken.79 76-What this means is that the :func:`echo` function applies some error77-correction in case the terminal is misconfigured instead of dying with a78-:exc:`UnicodeError`.80+What this means is that the {func}`echo` function applies some error correction in case the terminal is misconfigured81+instead of dying with a {exc}`UnicodeError`.82 80-The echo function also supports color and other styles in output. It81-will automatically remove styles if the output stream is a file. On82-Windows, colorama is automatically installed and used. See83-:ref:`ansi-colors`.83+The echo function also supports color and other styles in output. It will automatically remove styles if the output84+stream is a file. On Windows, colorama is automatically installed and used. See {ref}`ansi-colors`.85 85-If you don't need this, you can also use the `print()` construct /86-function.86+If you don't need this, you can also use the `print()` construct / function.87 88-Nesting Commands89-----------------88+## Nesting Commands89 91-Commands can be attached to other commands of type :class:`Group`. This92-allows arbitrary nesting of scripts. As an example here is a script that93-implements two commands for managing databases:90+Commands can be attached to other commands of type {class}`Group`. This allows arbitrary nesting of scripts. As an91+example here is a script that implements two commands for managing databases:92 93+```{eval-rst}94 .. click:example::96-95 @click.group()96 def cli():97 pass98 6 unmodified lines105 click.echo('Dropped the database')106 107 cli.add_command(initdb)108 cli.add_command(dropdb)109+```110 112-As you can see, the :func:`group` decorator works like the :func:`command`113-decorator, but creates a :class:`Group` object instead which can be given114-multiple subcommands that can be attached with :meth:`Group.add_command`.111+As you can see, the {func}`group` decorator works like the {func}`command` decorator, but creates a {class}`Group`112+object instead which can be given multiple subcommands that can be attached with {meth}`Group.add_command`.113 116-For simple scripts, it's also possible to automatically attach and create a117-command by using the :meth:`Group.command` decorator instead. The above118-script can instead be written like this:114+For simple scripts, it's also possible to automatically attach and create a command by using the {meth}`Group.command`115+decorator instead. The above script can instead be written like this:116 117+```{eval-rst}118 .. click:example::121-119 @click.group()120 def cli():121 pass122 4 unmodified lines127 @cli.command()128 def dropdb():129 click.echo('Dropped the database')130 134-You would then invoke the :class:`Group` in your entry points or other invocations::131+You would then invoke the :class:`Group` in your entry points or other invocations:132 133+.. click:example::134 if __name__ == '__main__':135 cli()136+```137 138+## Registering Commands Later139 140-Registering Commands Later141---------------------------140+Instead of using the `@group.command()` decorator, commands can be decorated with the plain `@command()` decorator141+and registered with a group later with `group.add_command()`. This could be used to split commands into multiple Python142+modules.143 143-Instead of using the ``@group.command()`` decorator, commands can be144-decorated with the plain ``@click.command()`` decorator and registered145-with a group later with ``group.add_command()``. This could be used to146-split commands into multiple Python modules.147-148-.. code-block:: python149-144+```{code-block} python145 @click.command()146 def greet():147 click.echo("Hello, World!")148+```149 154-.. code-block:: python155-150+```{code-block} python151 @click.group()152 def group():153 pass154 155 group.add_command(greet)156+```157 158+## Adding Parameters159 163-Adding Parameters164------------------160+To add parameters, use the {func}`option` and {func}`argument` decorators:161 166-To add parameters, use the :func:`option` and :func:`argument` decorators:167-162+```{eval-rst}163 .. click:example::169-164 @click.command()165 @click.option('--count', default=1, help='number of greetings')166 @click.argument('name')167 def hello(count, name):2 unmodified lines170 171 What it looks like:172 173 .. click:run::180-174 invoke(hello, args=['--help'], prog_name='python hello.py')175+```176 183-Switching to Entry Points184--------------------------177+## Switching to Entry Points178 186-In the code you wrote so far there is a block at the end of the file which187-looks like this: ``if __name__ == '__main__':``. This is traditionally188-how a standalone Python file looks like. With Click you can continue179+In the code you wrote so far there is a block at the end of the file which looks like this:180+`if __name__ == '__main__':`. This is traditionally how a standalone Python file looks like. With Click you can continue181 doing that, but a better way is to package your app with an entry point.182 183 There are two main (and many more) reasons for this:184 193-The first one is that installers automatically generate executable194-wrappers for Windows so your command line utilities work on Windows too.185+The first one is that installers automatically generate executable wrappers for Windows so your command line utilities186+work on Windows too.187 196-The second reason is that entry point scripts work with virtualenv on Unix197-without the virtualenv having to be activated. This is a very useful198-concept which allows you to bundle your scripts with all requirements into199-a virtualenv.188+The second reason is that entry point scripts work with virtualenv on Unix without the virtualenv having to be189+activated. This is a very useful concept which allows you to bundle your scripts with all requirements into a190+virtualenv.191 201-Click is perfectly equipped to work with that and in fact the rest of the202-documentation will assume that you are writing applications as distributed203-packages.192+Click is perfectly equipped to work with that and in fact the rest of the documentation will assume that you are writing193+applications as distributed packages.194 205-Look at the :doc:`entry-points` chapter before reading the rest as the examples206-assume that you will be using entry points.195+Look at the {doc}`entry-points` chapter before reading the rest as the examples assume that you will be using entry196+points.