forked from orbit-oss/flask
Merge pull request #1848 from RaHus/add_version_switch_flask_cli
Add version switch to flask cli
This commit is contained in:
commit
19b134002c
1 changed files with 26 additions and 3 deletions
29
flask/cli.py
29
flask/cli.py
|
|
@ -18,7 +18,7 @@ import click
|
|||
|
||||
from ._compat import iteritems, reraise
|
||||
from .helpers import get_debug_flag
|
||||
|
||||
from . import __version__
|
||||
|
||||
class NoAppException(click.UsageError):
|
||||
"""Raised if an application cannot be found or loaded."""
|
||||
|
|
@ -108,6 +108,22 @@ def find_default_import_path():
|
|||
return app
|
||||
|
||||
|
||||
def get_version(ctx, param, value):
|
||||
if not value or ctx.resilient_parsing:
|
||||
return
|
||||
message = 'Flask %(version)s\nPython %(python_version)s'
|
||||
click.echo(message % {
|
||||
'version': __version__,
|
||||
'python_version': sys.version,
|
||||
}, color=ctx.color)
|
||||
ctx.exit()
|
||||
|
||||
version_option = click.Option(['--version'],
|
||||
help='Show the flask version',
|
||||
expose_value=False,
|
||||
callback=get_version,
|
||||
is_flag=True, is_eager=True)
|
||||
|
||||
class DispatchingApp(object):
|
||||
"""Special application that dispatches to a flask application which
|
||||
is imported by name in a background thread. If an error happens
|
||||
|
|
@ -270,12 +286,19 @@ class FlaskGroup(AppGroup):
|
|||
|
||||
:param add_default_commands: if this is True then the default run and
|
||||
shell commands wil be added.
|
||||
:param add_version_option: adds the :option:`--version` option.
|
||||
:param create_app: an optional callback that is passed the script info
|
||||
and returns the loaded app.
|
||||
"""
|
||||
|
||||
def __init__(self, add_default_commands=True, create_app=None, **extra):
|
||||
AppGroup.__init__(self, **extra)
|
||||
def __init__(self, add_default_commands=True, create_app=None,
|
||||
add_version_option=True, **extra):
|
||||
params = list(extra.pop('params', None) or ())
|
||||
|
||||
if add_version_option:
|
||||
params.append(version_option)
|
||||
|
||||
AppGroup.__init__(self, params=params, **extra)
|
||||
self.create_app = create_app
|
||||
|
||||
if add_default_commands:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue