Skip to content

standalone_mode does not affect the help option #667

Closed

Description

@malkarouri

If we use standalone_mode=True passing arguments to command execution will not call sys.exit, except if the argument to the command is ["--help"].

From inside ipython:

In [12]: import click

In [13]: @click.command()
...: def hello():
...: print("hello, world")
...:

In [14]: hello.main([], standalone_mode=False)
hello, world

In [15]: hello.main(['wrong_arg'], standalone_mode=False)

UsageError Traceback (most recent call last)
in ()
...
UsageError: Got unexpected extra argument (wrong_arg)

In [16]: hello.main(['--help'], standalone_mode=False)
Usage: ipython [OPTIONS]

Options:
--help Show this message and exit.
An exception has occurred, use %tb to see the full traceback.

SystemExit: 0

/Users/malkarouri/Library/Python/2.7/lib/python/site-packages/IPython/core/interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Expected:
--help parameter in standalone mode does not call sys.exit.

Activity

  1. jamesmyatt commented on Mar 3, 2018

    @jamesmyatt

    I think you mean "standalone_mode=False", but I agree. The offending line is https://github.com/pallets/click/blob/master/click/core.py#L1030. Compare with the Command.main: https://github.com/pallets/click/blob/master/click/core.py#L707

    This is important since it makes debugging harder.

  2. added 4 commits that reference this issue on Aug 26, 2018
    1c45f26
    b912f0b
    5277922
    1602436
  3. added this to the 7.0 milestone on Sep 10, 2018
  4. added a commit that references this issue on Sep 17, 2018
    07e3e75
  5. added 2 commits that reference this issue on Oct 8, 2018
  6. added a commit that references this issue on Oct 29, 2018
  7. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  8. added
    help outputHelp text formatting, layout, and --help rendering
    parsingParsing, parameters, commands, chaining, context
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help outputHelp text formatting, layout, and --help renderingparsingParsing, parameters, commands, chaining, context

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions