From 574de7d77bc9ad69dc3784efa8b59024d969e9b1 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Fri, 31 Aug 2018 19:06:20 -0300 Subject: [PATCH] Fix #2897 - Add `extra_files` option to `flask run` CLI --- CHANGES.rst | 4 +++- docs/cli.rst | 14 ++++++++++++++ flask/cli.py | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1902cc85..454ae75a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,9 @@ Version 1.1 Unreleased +- Added support to ``extra_files`` argument in `flask run` CLI. (`#2898`_) + +.. _#2898: https://github.com/pallets/flask/pull/2898 Version 1.0.3 ------------- @@ -24,7 +27,6 @@ Unreleased .. _#2766: https://github.com/pallets/flask/issues/2766 .. _#2765: https://github.com/pallets/flask/pull/2765 - Version 1.0.2 ------------- diff --git a/docs/cli.rst b/docs/cli.rst index a69fa874..45f06a35 100644 --- a/docs/cli.rst +++ b/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 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 ~~~~~~~~~~~~~~ diff --git a/flask/cli.py b/flask/cli.py index 32f42c4c..75420037 100644 --- a/flask/cli.py +++ b/flask/cli.py @@ -746,9 +746,12 @@ def _validate_key(ctx, param, value): 'loading is enabled if the reloader is disabled.') @click.option('--with-threads/--without-threads', default=True, 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 def run_command(info, host, port, reload, debugger, eager_loading, - with_threads, cert): + with_threads, cert, extra_files): """Run a local development server. 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 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.')