Skip to content
Myr

Merge pull request #1848 from RaHus/add_version_switch_flask_cli

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

Add version switch to flask cli

authored by Armin Ronacher · committed by Armin Ronacher · parents fd1a355, 6b28ceb · Browse files · 1 file+26 added−3 removed
This commit

State

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

Diff stats

1 file+26 added−3 removed

  • other:+26 added−3 removed

1 file+26 added−3 removed

modified:flask/cli.py+26 added-3 removed
16 unmodified lines
17import click1819from ._compat import iteritems, reraise20from .helpers import get_debug_flag21from . import __version__222223class NoAppException(click.UsageError):24 """Raised if an application cannot be found or loaded."""2526
80 unmodified lines
107 return prepare_exec_for_file(app)108 return app109110111def get_version(ctx, param, value):112 if not value or ctx.resilient_parsing:113 return114 message = 'Flask %(version)s\nPython %(python_version)s'115 click.echo(message % {116 'version': __version__,117 'python_version': sys.version,118 }, color=ctx.color)119 ctx.exit()120121version_option = click.Option(['--version'],122 help='Show the flask version',123 expose_value=False,124 callback=get_version,125 is_flag=True, is_eager=True)126127class DispatchingApp(object):128 """Special application that dispatches to a flask application which129 is imported by name in a background thread. If an error happens130 it is is recorded and shows as part of the WSGI handling which in case
154 unmodified lines
285 For information as of why this is useful see :ref:`custom-scripts`.286287 :param add_default_commands: if this is True then the default run and288 shell commands wil be added.289 :param add_version_option: adds the :option:`--version` option.290 :param create_app: an optional callback that is passed the script info291 and returns the loaded app.292 """293277 def __init__(self, add_default_commands=True, create_app=None, **extra):278 AppGroup.__init__(self, **extra)294 def __init__(self, add_default_commands=True, create_app=None,295 add_version_option=True, **extra):296 params = list(extra.pop('params', None) or ())297298 if add_version_option:299 params.append(version_option)300301 AppGroup.__init__(self, params=params, **extra)302 self.create_app = create_app303304 if add_default_commands:305 self.add_command(run_command)
200 unmodified lines