Skip to content
Myr

Added a way to disable the standalone mode on main.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 8c369b9 · Browse files · 3 files+24 added−2 removed
This commit

State

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

Diff stats

3 files+24 added−2 removed

  • other:+24 added−2 removed

3 files+24 added−2 removed

modified:click/core.py+21 added-2 removed
475 unmodified lines
476 implementation is raising a not implemented error.477 """478 raise NotImplementedError('Base commands are not invokable by default')479480 def main(self, args=None, prog_name=None, complete_var=None, **extra):480 def main(self, args=None, prog_name=None, complete_var=None,481 standalone_mode=True, **extra):482 """This is the way to invoke a script with all the bells and483 whistles as a command line application. This will always terminate484 the application after a call. If this is not wanted, ``SystemExit``485 needs to be caught.486487 This method is also available by directly calling the instance of488 a :class:`Command`.489490 .. versionadded:: 3.0491 Added the `standalone_mode` flag to control the standalone mode.492493 :param args: the arguments that should be used for parsing. If not494 provided, ``sys.argv[1:]`` is used.495 :param prog_name: the program name that should be used. By default496 the program name is constructed by taking the file
1 unmodified line
498 :param complete_var: the environment variable that controls the499 bash completion support. The default is500 ``"_<prog_name>_COMPLETE"`` with prog name in501 uppercase.502 :param standalone_mode: the default behavior is to invoke the script503 in standalone mode. Click will then504 handle exceptions and convert them into505 error messages and the function will never506 return but shut down the interpreter. If507 this is set to `False` they will be508 propagated to the caller and the return509 value of this function is the return value510 of :meth:`invoke`.511 :param extra: extra keyword arguments are forwarded to the context512 constructor. See :class:`Context` for more information.513 """514 # If we are in Python 3, we will verify that the environment is
28 unmodified lines
543544 try:545 try:546 with self.make_context(prog_name, args, **extra) as ctx:534 self.invoke(ctx)547 rv = self.invoke(ctx)548 if not standalone_mode:549 return rv550 ctx.exit()551 except (EOFError, KeyboardInterrupt):552 echo(file=sys.stderr)553 raise Abort()554 except ClickException as e:555 if not standalone_mode:556 raise557 e.show()558 sys.exit(e.exit_code)559 except Abort:560 if not standalone_mode:561 raise562 echo('Aborted!', file=sys.stderr)563 sys.exit(1)564565 def __call__(self, *args, **kwargs):
896 unmodified lines
modified:docs/index.rst+1 added
71 unmodified lines
72 advanced73 testing74 utils75 bashcomplete76 exceptions77 python37879API Reference80-------------
18 unmodified lines
modified:CHANGES+2 added
25 unmodified lines
26- Added support for defaults on options with `multiple` and27 options and arguments with `nargs != 1`.28- label passed to `progressbar` is no longer rendered with29 whitespace stripped.30- added a way to disable the standalone mode of the `main`31 method on a Click command to be able to handle errors better.3233Version 2.634-----------35
111 unmodified lines