Exit code changed for command showing help message when arguments are not provided
Defining a simple entry-point group:
from __future__ import annotations
import click
from .sys_info import run as sys_info
@click.group()
def run() -> None:
"""Main package entry-point.""" # noqa: D401
run.add_command(sys_info)
And executing the corresponding command without an arguments shows the help message, e.g.
$ my_click_cmd
Usage: my_click_cmd [OPTIONS] COMMAND [ARGS]...
Main package entry-point.
Options:
--help Show this message and exit.
Commands:
sys-info Run sys_info() command.
But now returns exit code 2 instead of 0 as in click<8.2.0. $ my_click_cmd --help, providing explicitly the --help option returns the same message with exit code 0.
Is this an intended backward incompatible change (undocumented in the changelog), or an introduced bug?
The issue https://github.com/pallets/click/issues/1394 was discussed, then addressed by the PR https://github.com/pallets/click/pull/1489, it's intentional. --help is a deliberate request for that output, and so is treated as a successful run with 0. no_args_is_help is essentially a usage error, and so acts the same with 2.
We'll update the release notes.
@davidism Thank you very much for your work on click. But I consider changing exit codes a breaking release. We have to release a new version of a software used by many production systems because our software cannot be installed anymore because click is not pinned.
I agree that a non-zero exit makes sense. But please do not fix this in a non-breaking release.
Here's our version policy, which has remained the same for the last decade at least: https://palletsprojects.com/versions
The B number is considered a "feature" release. Increasing this number indicates adding new features, and may deprecate existing code or remove previously deprecated code.
When writing an application, you must use a tool like pip-compile to pin your application's full dependency tree. This gives you reproducible deployments, allowing you to control when you get updates.
The command no_args_is_help is relevant. click command