Skip to content
Myr

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

2 files+58 added−3 removed

modified:docs/command-line-reference.md+3 added-1 removed
modified:docs/exceptions.rst+55 added-2 removed
1Exception Handling2==================1.. _exception-handling-exit-codes:23Exception Handling and Exit Codes4==================================56.. currentmodule:: click78Click internally uses exceptions to signal various error conditions that9the user of the application might have caused. Primarily this is things10like incorrect usage.1112.. contents::13 :depth: 114 :local:1516Where are Errors Handled?17-------------------------1819Click's main error handling is happening in :meth:`Command.main`. In
56 unmodified lines
76 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.808182.. _help-page-exit-codes:8384Help Pages and Exit Codes85--------------------------8687Triggering 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.8889For clarity, here is an example.9091.. click:example::9293 @click.group('printer_group')94 def printer_group():95 pass9697 @printer_group.command('printer')98 @click.option('--this')99 def printer(this):100 if this:101 click.echo(this)102103.. click:run::104 invoke(printer_group, args=['--help'])105106The above invocation returns exit code 0.107108.. click:run::109 invoke(printer_group, args=[])110111The 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.112113.. click:example::114115 @click.group('printer_group', no_args_is_help=False)116 def printer_group():117 pass118119 @printer_group.command('printer')120 @click.option('--this')121 def printer(this):122 if this:123 click.echo(this)124125.. click:run::126 invoke(printer_group, args=[])