Skip to content

Commit 3fc7c77

Browse files
Update docs
1 parent 458f2d2 commit 3fc7c77

File tree

501 files changed

+35808
-3374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

501 files changed

+35808
-3374
lines changed

debian/control

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ Depends: ${misc:Depends},
173173
Description: View devdocs offline in a terminal
174174
This package contains offline data for chef.
175175

176+
Package: devdocs-data-click
177+
Architecture: all
178+
Depends: ${misc:Depends},
179+
devdocs (= ${binary:Version})
180+
Description: View devdocs offline in a terminal
181+
This package contains offline data for click.
182+
176183
Package: devdocs-data-clojure
177184
Architecture: all
178185
Depends: ${misc:Depends},
@@ -957,6 +964,13 @@ Depends: ${misc:Depends},
957964
Description: View devdocs offline in a terminal
958965
This package contains offline data for mongoose.
959966

967+
Package: devdocs-data-nextjs
968+
Architecture: all
969+
Depends: ${misc:Depends},
970+
devdocs (= ${binary:Version})
971+
Description: View devdocs offline in a terminal
972+
This package contains offline data for nextjs.
973+
960974
Package: devdocs-data-nginx
961975
Architecture: all
962976
Depends: ${misc:Depends},

debian/devdocs-data-click.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
usr/share/devdocs/html/click

debian/devdocs-data-nextjs.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
usr/share/devdocs/html/nextjs

html/click/advanced/index.html

Lines changed: 185 additions & 0 deletions
Large diffs are not rendered by default.

html/click/api/index.html

Lines changed: 1730 additions & 0 deletions
Large diffs are not rendered by default.

html/click/arguments/index.html

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<h1 id="id1">Arguments</h1> <p>Arguments work similarly to <a class="reference internal" href="../options/index.html#options"><span class="std std-ref">options</span></a> but are positional. They also only support a subset of the features of options due to their syntactical nature. Click will also not attempt to document arguments for you and wants you to <a class="reference internal" href="../documentation/index.html#documenting-arguments"><span class="std std-ref">document them manually</span></a> in order to avoid ugly help pages.</p> <section id="basic-arguments"> <h2>Basic Arguments</h2> <p>The most basic option is a simple string argument of one value. 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 <a class="reference internal" href="../api/index.html#click.STRING" title="click.STRING"><code>STRING</code></a>.</p> <p>Example:</p> <pre data-language="python">@click.command()
2+
@click.argument('filename')
3+
def touch(filename):
4+
"""Print FILENAME."""
5+
click.echo(filename)
6+
</pre> <p>And what it looks like:</p> <pre data-language="shell">$ touch foo.txt
7+
foo.txt
8+
</pre> </section> <section id="variadic-arguments"> <h2>Variadic Arguments</h2> <p>The second most common version is variadic arguments where a specific (or unlimited) number of arguments is accepted. This can be controlled with the <code>nargs</code> parameter. If it is set to <code>-1</code>, then an unlimited number of arguments is accepted.</p> <p>The value is then passed as a tuple. Note that only one argument can be set to <code>nargs=-1</code>, as it will eat up all arguments.</p> <p>Example:</p> <pre data-language="python">@click.command()
9+
@click.argument('src', nargs=-1)
10+
@click.argument('dst', nargs=1)
11+
def copy(src, dst):
12+
"""Move file SRC to DST."""
13+
for fn in src:
14+
click.echo(f"move {fn} to folder {dst}")
15+
</pre> <p>And what it looks like:</p> <pre data-language="shell">$ copy foo.txt bar.txt my_folder
16+
move foo.txt to folder my_folder
17+
move bar.txt to folder my_folder
18+
</pre> <p>Note that this is not how you would write this application. The reason for this is that in this particular example the arguments are defined as strings. Filenames, however, are not strings! They might be on certain operating systems, but not necessarily on all. For better ways to write this, see the next sections.</p> <div class="admonition-note-on-non-empty-variadic-arguments admonition"> <p class="admonition-title">Note on Non-Empty Variadic Arguments</p> <p>If you come from <code>argparse</code>, you might be missing support for setting <code>nargs</code> to <code>+</code> to indicate that at least one argument is required.</p> <p>This is supported by setting <code>required=True</code>. However, this should not be used if you can avoid it as we believe scripts should gracefully degrade into becoming noops if a variadic argument is empty. The reason for this is that very often, scripts are invoked with wildcard inputs from the command line and they should not error out if the wildcard is empty.</p> </div> </section> <section id="file-arguments"> <h2 id="file-args">File Arguments</h2> <p>Since all the examples have already worked with filenames, it makes sense to explain how to deal with files properly. Command line tools are more fun if they work with files the Unix way, which is to accept <code>-</code> as a special file that refers to stdin/stdout.</p> <p>Click supports this through the <a class="reference internal" href="../api/index.html#click.File" title="click.File"><code>click.File</code></a> type which intelligently handles files for you. It also deals with Unicode and bytes correctly for all versions of Python so your script stays very portable.</p> <p>Example:</p> <pre data-language="python">@click.command()
19+
@click.argument('input', type=click.File('rb'))
20+
@click.argument('output', type=click.File('wb'))
21+
def inout(input, output):
22+
"""Copy contents of INPUT to OUTPUT."""
23+
while True:
24+
chunk = input.read(1024)
25+
if not chunk:
26+
break
27+
output.write(chunk)
28+
</pre> <p>And what it does:</p> <pre data-language="shell">$ inout - hello.txt
29+
hello
30+
^D
31+
$ inout hello.txt -
32+
hello
33+
</pre> </section> <section id="file-path-arguments"> <h2>File Path Arguments</h2> <p>In the previous example, the files were opened immediately. But what if we just want the filename? The naïve way is to use the default string argument type. The <a class="reference internal" href="../api/index.html#click.Path" title="click.Path"><code>Path</code></a> type has several checks available which raise nice errors if they fail, such as existence. Filenames in these error messages are formatted with <a class="reference internal" href="../api/index.html#click.format_filename" title="click.format_filename"><code>format_filename()</code></a>, so any undecodable bytes will be printed nicely.</p> <p>Example:</p> <pre data-language="python">@click.command()
34+
@click.argument('filename', type=click.Path(exists=True))
35+
def touch(filename):
36+
"""Print FILENAME if the file exists."""
37+
click.echo(click.format_filename(filename))
38+
</pre> <p>And what it does:</p> <pre data-language="shell">$ touch hello.txt
39+
hello.txt
40+
41+
$ touch missing.txt
42+
Usage: touch [OPTIONS] FILENAME
43+
Try 'touch --help' for help.
44+
45+
Error: Invalid value for 'FILENAME': Path 'missing.txt' does not exist.
46+
</pre> </section> <section id="file-opening-safety"> <h2>File Opening Safety</h2> <p>The <code>FileType</code> type has one problem it needs to deal with, and that is to decide when to open a file. The default behavior is to be “intelligent” about it. What this means is that it will open stdin/stdout and files opened for reading immediately. This will give the user direct feedback when a file cannot be opened, but it will only open files for writing the first time an IO operation is performed by automatically wrapping the file in a special wrapper.</p> <p>This behavior can be forced by passing <code>lazy=True</code> or <code>lazy=False</code> to the constructor. If the file is opened lazily, it will fail its first IO operation by raising an <a class="reference internal" href="../api/index.html#click.FileError" title="click.FileError"><code>FileError</code></a>.</p> <p>Since files opened for writing will typically immediately empty the file, the lazy mode should only be disabled if the developer is absolutely sure that this is intended behavior.</p> <p>Forcing lazy mode is also very useful to avoid resource handling confusion. If a file is opened in lazy mode, it will receive a <code>close_intelligently</code> method that can help figure out if the file needs closing or not. This is not needed for parameters, but is necessary for manually prompting with the <a class="reference internal" href="../api/index.html#click.prompt" title="click.prompt"><code>prompt()</code></a> function as you do not know if a stream like stdout was opened (which was already open before) or a real file that needs closing.</p> <p>Starting with Click 2.0, it is also possible to open files in atomic mode by passing <code>atomic=True</code>. In atomic mode, all writes go into a separate file in the same folder, and upon completion, the file will be moved over to the original location. This is useful if a file regularly read by other users is modified.</p> </section> <section id="environment-variables"> <h2>Environment Variables</h2> <p>Like options, arguments can also grab values from an environment variable. Unlike options, however, this is only supported for explicitly named environment variables.</p> <p>Example usage:</p> <pre data-language="python">@click.command()
47+
@click.argument('src', envvar='SRC', type=click.File('r'))
48+
def echo(src):
49+
"""Print value of SRC environment variable."""
50+
click.echo(src.read())
51+
</pre> <p>And from the command line:</p> <pre data-language="shell">$ export SRC=hello.txt
52+
$ echo
53+
Hello World!
54+
</pre> <p>In that case, it can also be a list of different environment variables where the first one is picked.</p> <p>Generally, this feature is not recommended because it can cause the user a lot of confusion.</p> </section> <section id="option-like-arguments"> <h2>Option-Like Arguments</h2> <p>Sometimes, you want to process arguments that look like options. For instance, imagine you have a file named <code>-foo.txt</code>. If you pass this as an argument in this manner, Click will treat it as an option.</p> <p>To solve this, Click does what any POSIX style command line script does, and that is to accept the string <code>--</code> as a separator for options and arguments. After the <code>--</code> marker, all further parameters are accepted as arguments.</p> <p>Example usage:</p> <pre data-language="python">@click.command()
55+
@click.argument('files', nargs=-1, type=click.Path())
56+
def touch(files):
57+
"""Print all FILES file names."""
58+
for filename in files:
59+
click.echo(filename)
60+
</pre> <p>And from the command line:</p> <pre data-language="shell">$ touch -- -foo.txt bar.txt
61+
-foo.txt
62+
bar.txt
63+
</pre> <p>If you don’t like the <code>--</code> marker, you can set ignore_unknown_options to True to avoid checking unknown options:</p> <pre data-language="python">@click.command(context_settings={"ignore_unknown_options": True})
64+
@click.argument('files', nargs=-1, type=click.Path())
65+
def touch(files):
66+
"""Print all FILES file names."""
67+
for filename in files:
68+
click.echo(filename)
69+
</pre> <p>And from the command line:</p> <pre data-language="shell">$ touch -foo.txt bar.txt
70+
-foo.txt
71+
bar.txt
72+
</pre> </section><div class="_attribution">
73+
<p class="_attribution-p">
74+
&copy; Copyright 2014 Pallets.<br>Licensed under the BSD 3-Clause License.<br>We are not supported nor endorsed by Pallets.<br>
75+
<a href="https://click.palletsprojects.com/en/8.1.x/arguments/" class="_attribution-link">https://click.palletsprojects.com/en/8.1.x/arguments/</a>
76+
</p>
77+
</div>

0 commit comments

Comments
 (0)