Skip to content

Commit 1eceadc

Browse files
committed
Default use_debugger and use_reloader to app.debug
1 parent 5bd5331 commit 1eceadc

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

flask_script/commands.py

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class InvalidCommand(Exception):
1919
"""\
2020
This is a generic error for "bad" commands.
2121
It is not used in Flask-Script itself, but you should throw
22-
this error (or one derived from it) in your command handlers,
22+
this error (or one derived from it) in your command handlers,
2323
and your main code should display this error's message without
2424
a stack trace.
2525
@@ -335,7 +335,7 @@ class Server(Command):
335335

336336
help = description = 'Runs the Flask development server i.e. app.run()'
337337

338-
def __init__(self, host='127.0.0.1', port=5000, use_debugger=False,
338+
def __init__(self, host='127.0.0.1', port=5000, use_debugger=None,
339339
use_reloader=None, threaded=False, processes=1,
340340
passthrough_errors=False, **options):
341341

@@ -374,55 +374,29 @@ def get_options(self):
374374
action='store_true',
375375
dest='passthrough_errors',
376376
default=self.passthrough_errors),
377-
)
378-
379-
if self.use_debugger:
380-
options += (Option('-d', '--debug',
381-
action='store_true',
382-
dest='use_debugger',
383-
help="(no-op for compatibility. USE '--no-debug' IN PRODCUTION CODE)",
384-
default=True),)
385-
options += (Option('-D', '--no-debug',
386-
action='store_false',
387-
dest='use_debugger',
388-
help='disable the Werkzeug debugger',
389-
default=True),)
390-
391-
else:
392-
options += (Option('-d', '--debug',
393-
action='store_true',
394-
dest='use_debugger',
395-
help='enable the Werkzeug debugger (DO NOT use in production code)',
396-
default=False),)
397-
options += (Option('-D', '--no-debug',
398-
action='store_false',
399-
dest='use_debugger',
400-
help="(no-op for compatibility)",
401-
default=False),)
402-
403-
if self.use_reloader:
404-
options += (Option('-r', '--reload',
405-
action='store_true',
406-
dest='use_reloader',
407-
help="(no-op for compatibility)",
408-
default=True),)
409-
options += (Option('-R', '--no-reload',
410-
action='store_false',
411-
dest='use_reloader',
412-
help='do not monitor Python files for changes',
413-
default=True),)
414377

415-
else:
416-
options += (Option('-r', '--reload',
417-
action='store_true',
418-
dest='use_reloader',
419-
help='monitor Python files for changes',
420-
default=False),)
421-
options += (Option('-R', '--no-reload',
422-
action='store_false',
423-
dest='use_reloader',
424-
help="(no-op for compatibility)",
425-
default=False),)
378+
Option('-d', '--debug',
379+
action='store_true',
380+
dest='use_debugger',
381+
help='enable the Werkzeug debugger (DO NOT use in production code)',
382+
default=self.use_debugger),
383+
Option('-D', '--no-debug',
384+
action='store_false',
385+
dest='use_debugger',
386+
help='disable the Werkzeug debugger',
387+
default=self.use_debugger),
388+
389+
Option('-r', '--reload',
390+
action='store_true',
391+
dest='use_reloader',
392+
help='monitor Python files for changes (not 100% safe for production use)',
393+
default=self.use_reloader),
394+
Option('-R', '--no-reload',
395+
action='store_false',
396+
dest='use_reloader',
397+
help='do not monitor Python files for changes',
398+
default=self.use_reloader),
399+
)
426400

427401
return options
428402

@@ -431,6 +405,10 @@ def __call__(self, app, host, port, use_debugger, use_reloader,
431405
# we don't need to run the server in request context
432406
# so just run it directly
433407

408+
if use_debugger is None:
409+
use_debugger = app.debug
410+
if use_reloader is None:
411+
use_reloader = app.debug
434412
app.run(host=host,
435413
port=port,
436414
debug=use_debugger,

0 commit comments

Comments
 (0)