close
Skip to content

standalone_mode does not affect the help option #667

@malkarouri

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions