Skip to content

Not specifying a group's command exits with code 0 #1486

@plannigan

Description

@plannigan

When a group is created with multiple commands, but the script is called without any commands, the exit code is 0. It looks like this line just needs to be changed to have an exit code. But it's not clear if ctx.fail() should be used instead.

Example Code

import click

@click.group()
def cli():
    print("in group")

@cli.command()
def foo():
    print("foo")

@cli.command()
def bar():
    print("bar")

if __name__ == "__main__":
    print("before group")
    cli()

Expected Behavior

A non-zero exit code.

Actual Behavior

$ python click_poc.py 
before group
Usage: click_poc.py [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  bar
  foo
$ echo $?
0

Environment

  • Python version: Python 3.8.0
  • Click version: Click==7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions