Skip to content
Myr

Rewrite arguments docs more nicely.

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

authored by unknown · committed by unknown · parent 82ffa4b · Browse files · 3 files+14 added−12 removed
This commit

State

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

Diff stats

3 files+14 added−12 removed

  • other:+14 added−12 removed

3 files+14 added−12 removed

modified:docs/arguments.rst+11 added-11 removed
3 unmodified lines
4=========56.. currentmodule:: click78Arguments are:9910* Are positional in nature11* Are very much like a limited version of :ref:`options <options>`12* But also can take an arbitrary number of inputs13* Must be :ref:`documented manually <documenting-arguments>`11* Similar to a limited version of :ref:`options <options>` that can take an arbitrary number of inputs12* :ref:`documented manually <documenting-arguments>`1314Useful and often used kwargs are:1516* ``default`` : Passes a default
20 unmodified lines
3738 invoke(touch, args=['foo.txt'])394042Not sure if should include : If no type is provided, the type of the default value is used, and if no default value is provided, the type is assumed to be STRING.41An argument may be assigned a :ref:`parameter type <parameter-types>`. If no type is provided, the type of the default value is used. If no default value is provided, the type is assumed to be STRING.4243.. admonition:: Note on Required Arguments4445 It is possible to make an argument required by setting ``required=True``. It is not recommended since we think command line tools should gracefully degrade into becoming no ops. We think this because command line tools are often invoked with wildcard inputs and they should not error out if the wildcard is empty.4647Multiple Arguments48-----------------------------------4950To set the number of argument use the ``nargs`` kwarg. It can be set to any positive integer and -1. Setting it to -1, makes the number of arguments arbitrary (which is called variadic) and can only be used once. The arguments are then packed as a tuple and passed to the function.
13 unmodified lines
64.. click:run::6566 invoke(copy, args=['foo.txt', 'usr/david/foo.txt', 'usr/mitsuko/foo.txt'])6768.. admonition:: Note on Handling Files.65Note this example is not how you would handle files and files paths, since it passes them in as strings. For more see :ref:`handling-files`.69 This is not how you would handle files and files paths, since it passes them in as strings. For more see :ref:`handling-files`.7067.. admonition:: Note on Required Arguments6869 It is not recommended, but you may make at least one argument required by setting ``required=True``. It is not recommended since we think command line tools should gracefully degrade into becoming noops. We think this because command line tools are often invoked with wildcard inputs and they should not error out if the wildcard is empty.7071Argument Escape Sequences72---------------------------7374If you want to process arguments that look like options, like a file named ``-foo.txt``, you must pass the ``--`` separator first. After you pass the ``--``, you may only pass arguments. This is a common feature for POSIX command line tools.74If you want to process arguments that look like options, like a file named ``-foo.txt`` or ``--foo.txt`` , you must pass the ``--`` separator first. After you pass the ``--``, you may only pass arguments. This is a common feature for POSIX command line tools.7576Example usage:7778.. click:example::
57 unmodified lines
modified:docs/index.rst+1 added-1 removed
71 unmodified lines
72 setuptools73 parameters74 options75 arguments76 handling_files76 commands77 prompts78 handling_files79 documentation80 complex81 advanced82 testing
27 unmodified lines
modified:docs/parameters.rst+2 added
51 unmodified lines
52.. click:run::5354 invoke(multi_echo, ['--times=3', 'index.txt'], prog_name='multi_echo')5556.. _parameter-types:5758Parameter Types59---------------6061The supported parameter types are:
78 unmodified lines