Browse Source

Fix #2897 - Add `extra_files` option to `flask run` CLI

pull/2898/head
Bruno Rocha 6 years ago
parent
commit
574de7d77b
  1. 4
      CHANGES.rst
  2. 14
      docs/cli.rst
  3. 8
      flask/cli.py

4
CHANGES.rst

@ -9,6 +9,9 @@ Version 1.1
Unreleased Unreleased
- Added support to ``extra_files`` argument in `flask run` CLI. (`#2898`_)
.. _#2898: https://github.com/pallets/flask/pull/2898
Version 1.0.3 Version 1.0.3
------------- -------------
@ -24,7 +27,6 @@ Unreleased
.. _#2766: https://github.com/pallets/flask/issues/2766 .. _#2766: https://github.com/pallets/flask/issues/2766
.. _#2765: https://github.com/pallets/flask/pull/2765 .. _#2765: https://github.com/pallets/flask/pull/2765
Version 1.0.2 Version 1.0.2
------------- -------------

14
docs/cli.rst

@ -202,6 +202,20 @@ command, instead of ``flask run --port 8000``:
These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to
control default command options. control default command options.
To define a list of files the reloader should watch additionally to the modules
as in ``extra_files`` argument used in the ``app.run`` and ``werkzeug.serving.run_simple``
you can either use the ``--extra-files`` (or multiple ``-f``) option or define the
``FLASK_RUN_EXTRA_FILES`` environment variable.
.. code-block:: none
# on windows use ``;`` instead of ``:`` to separate paths
export FLASK_RUN_EXTRA_FILES=/path/to/file1:/path/to/file2
flask run
* Running on http://127.0.0.1:8000/
* Detected change in '/path/to/file1', reloading
On command line the same can be achieved with ``flask run -f /path/to/file1 -f /path/to/file2``.
Disable dotenv Disable dotenv
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~

8
flask/cli.py

@ -746,9 +746,12 @@ def _validate_key(ctx, param, value):
'loading is enabled if the reloader is disabled.') 'loading is enabled if the reloader is disabled.')
@click.option('--with-threads/--without-threads', default=True, @click.option('--with-threads/--without-threads', default=True,
help='Enable or disable multithreading.') help='Enable or disable multithreading.')
@click.option('--extra-files', '-f',
multiple=True, default=None, type=click.Path(),
help='Files reloader should watch additionally to the modules')
@pass_script_info @pass_script_info
def run_command(info, host, port, reload, debugger, eager_loading, def run_command(info, host, port, reload, debugger, eager_loading,
with_threads, cert): with_threads, cert, extra_files):
"""Run a local development server. """Run a local development server.
This server is for development purposes only. It does not provide This server is for development purposes only. It does not provide
@ -773,7 +776,8 @@ def run_command(info, host, port, reload, debugger, eager_loading,
from werkzeug.serving import run_simple from werkzeug.serving import run_simple
run_simple(host, port, app, use_reloader=reload, use_debugger=debugger, run_simple(host, port, app, use_reloader=reload, use_debugger=debugger,
threaded=with_threads, ssl_context=cert) threaded=with_threads, ssl_context=cert,
extra_files=extra_files)
@click.command('shell', short_help='Runs a shell in the app context.') @click.command('shell', short_help='Runs a shell in the app context.')

Loading…
Cancel
Save