Simplified click integration a bit
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 32d3224 · Browse files · 2 files·+14 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+14 added−28 removed
- other:+14 added−28 removed
Provenance
- Commit
7321a48- Tree
3bf721b- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
32d3224
2 files changed+14 added−28 removed
modified:flask/app.py+2 added-2 removed
9 unmodified lines10 """11 12 import os13 import sys14+import click15 from threading import Lock16 from datetime import timedelta17 from itertools import chain18 from functools import update_wrapper15 unmodified lines34 from .templating import DispatchingJinjaLoader, Environment, \35 _default_template_ctx_processor36 from .signals import request_started, request_finished, got_request_exception, \37 request_tearing_down, appcontext_tearing_down37-from .cli import make_default_cli38 from ._compat import reraise, string_types, text_type, integer_types39 40 # a lock used for logger initialization41 _logger_lock = Lock()501 unmodified lines543 #: application has been discovered. The default commands are544 #: provided by Flask itself and can be overridden.545 #:546 #: This is an instance of a :class:`click.Group` object.547- self.cli = make_default_cli(self)547+ self.cli = click.Group(self)548 549 def _get_error_handlers(self):550 from warnings import warn551 warn(DeprecationWarning('error_handlers is deprecated, use the '1372 unmodified linesmodified:flask/cli.py+12 added-26 removed
129 unmodified lines130 rv = self._load_unlocked()131 return rv(environ, start_response)132 133 134-def _no_such_app():135- raise NoAppException('Could not locate Flask application. '136- 'You did not provide FLASK_APP or the '137- '--app parameter.')138-139-134 class ScriptInfo(object):135 """Help object to deal with Flask applications. This is usually not136 necessary to interface with as it's used internally in the dispatching137 to click.23 unmodified lines161 if self.create_app is not None:162 rv = self.create_app(self)163 else:164 if self.app_import_path is None:171- _no_such_app()165+ raise NoAppException('Could not locate Flask application. '166+ 'You did not provide FLASK_APP or the '167+ '--app parameter.')168 rv = locate_app(self.app_import_path)169 if self.debug is not None:170 rv.debug = self.debug171 self._loaded_app = rv241 unmodified lines413 )414 code.interact(banner=banner, local=app.make_shell_context())415 416 421-def make_default_cli(app):422- """Creates the default click object for the app itself. Currently423- there are no default commands registered because all builtin commands424- are registered on the actual cmd object here.425- """426- return click.Group()417+cli = FlaskGroup(help="""\418+This shell command acts as general utility script for Flask applications.419 420+It loads the application configured (either through the FLASK_APP environment421+variable or the --app parameter) and then provides commands either provided422+by the application or Flask itself.423 429-@click.group(cls=FlaskGroup)430-def cli(**params):431- """432- This shell command acts as general utility script for Flask applications.424+The most useful commands are the "run" and "shell" command.425 434- It loads the application configured (either through the FLASK_APP environment435- variable or the --app parameter) and then provides commands either provided436- by the application or Flask itself.426+Example usage:427 438- The most useful commands are the "run" and "shell" command.428+ flask --app=hello --debug run429+""")430 440- Example usage:431 442- flask --app=hello --debug run443- """444-445-432 def main(as_module=False):433 this_module = __package__ + '.cli'434 args = sys.argv[1:]435 18 unmodified lines