Document help page exit codes (#3122)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents a2623d0, c150f4d · Browse files · 2 files·+58 added−3 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+58 added−3 removed
- other:+58 added−3 removed
Provenance
- Commit
7b4e59c- Tree
d13e07c- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
a2623d0- Parent 2
c150f4d
2 files changed+58 added−3 removed
modified:docs/command-line-reference.md+3 added-1 removed
8 unmodified lines9101112131415161726 unmodified lines44454647474849508 unmodified lineslocal: true---```
(exit-codes)=## Exit Codes
When a command is executed from the command line, then an exit code is return. The exit code, also called exit status or exit status code, is a positive integer that tells you whether the command executed with or without errors.
26 unmodified lines
.. code-block:: text
> echo %ERRORLEVEL%
```
For Click specific behavior on exit codes, see {ref}`exception-handling-exit-codes`.modified:docs/exceptions.rst+55 added-2 removed
1-Exception Handling2-==================1+.. _exception-handling-exit-codes:2 3+Exception Handling and Exit Codes4+==================================5+6 .. currentmodule:: click7 8 Click internally uses exceptions to signal various error conditions that9 the user of the application might have caused. Primarily this is things10 like incorrect usage.11 12+.. contents::13+ :depth: 114+ :local:15+16 Where are Errors Handled?17 -------------------------18 19 Click's main error handling is happening in :meth:`Command.main`. In56 unmodified lines76 are raised from a callback Click will automatically augment it with77 the parameter name if possible.78 * :exc:`FileError` this is an error that is raised by the79 :exc:`FileType` if Click encounters issues opening the file.80+81+82+.. _help-page-exit-codes:83+84+Help Pages and Exit Codes85+--------------------------86+87+Triggering the a help page intentionally (by passing in ``--help``) returns exit code 0. If a help page is displayed due to incorrect user input, the program returns exit code 2. See :ref:`exit-codes` for more general information.88+89+For clarity, here is an example.90+91+.. click:example::92+93+ @click.group('printer_group')94+ def printer_group():95+ pass96+97+ @printer_group.command('printer')98+ @click.option('--this')99+ def printer(this):100+ if this:101+ click.echo(this)102+103+.. click:run::104+ invoke(printer_group, args=['--help'])105+106+The above invocation returns exit code 0.107+108+.. click:run::109+ invoke(printer_group, args=[])110+111+The above invocation returns exit code 2 since the user invoked the command incorrectly. However, since this is such a common error when first using a command, Click invokes the help page for the user. To see that `printer-group` is an invalid invocation, turn `no_args_is_help` off.112+113+.. click:example::114+115+ @click.group('printer_group', no_args_is_help=False)116+ def printer_group():117+ pass118+119+ @printer_group.command('printer')120+ @click.option('--this')121+ def printer(this):122+ if this:123+ click.echo(this)124+125+.. click:run::126+ invoke(printer_group, args=[])