Skip to content
Myr

Add section for help page and exit codes and cross link

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

authored by Edward Girling · committed by Edward Girling · parent 6707116 · Browse files · 2 files+45 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+45 added−3 removed

  • other:+45 added−3 removed

2 files+45 added−3 removed

modified:docs/command-line-reference.md+4 added-1 removed
modified:docs/exceptions.rst+41 added-2 removed
1Exception Handling2==================1.. _exception-handling-exit-codes23Exception 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 display due to incorrect user provided input, the program returns exit code 2. See :ref:`exit-codes` for more on exit codes.888990.. click:example::9192 @click.group()93 def printer_group():94 pass9596 @printer_group.command('printer')97 @click.option('--this')98 def printer(this):99 if this:100 click.echo(this)101102103.. click:run::104 invoke(printer_group, args=[])105106The above invocation returns exit code 2 since the user invoked the command incorrect. However, since this is such a common error when first using a command, Click invokes the help page for the user.107108109.. click:run::110 invoke(printer_group, args=['--help'])111112The above invocation returns exit code 0.