From 283091437b3e82adf5aa992761e8baa30bc219e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Fri, 13 May 2022 14:48:15 +0200 Subject: [PATCH] [watchmedo] Fix broken parsing of boolean arguments (#887) --- changelog.rst | 3 ++- src/watchdog/watchmedo.py | 37 ++++++++++++++++--------------------- tests/test_0_watchmedo.py | 4 +++- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/changelog.rst b/changelog.rst index 1b3a1ef03..a6027fea9 100644 --- a/changelog.rst +++ b/changelog.rst @@ -10,7 +10,8 @@ Changelog - Fix adding failed emitters on observer schedule. (`#872 `_) - [watchmedo] Fix broken parsing of ``--kill-after`` argument for the ``auto-restart`` command. (`#870 `_) -- Thanks to our beloved contributors: @taleinat, @kianmeng, @palfrey, @IlayRosenberg +- [watchmedo] Fix broken parsing of boolean arguments. (`#855 `_) +- Thanks to our beloved contributors: @taleinat, @kianmeng, @palfrey, @IlayRosenberg, @BoboTiG 2.1.7 ~~~~~ diff --git a/src/watchdog/watchmedo.py b/src/watchdog/watchmedo.py index a3d1fd8a8..b76b8c0a3 100755 --- a/src/watchdog/watchmedo.py +++ b/src/watchdog/watchmedo.py @@ -213,22 +213,23 @@ def schedule_tricks(observer, tricks, pathname, recursive): type=float, help='Use this as the polling interval/blocking timeout (in seconds).'), argument('--recursive', + action='store_true', default=True, help='Recursively monitor paths.'), argument('--debug-force-polling', - default=False, + action='store_true', help='[debug] Forces polling.'), argument('--debug-force-kqueue', - default=False, + action='store_true', help='[debug] Forces BSD kqueue(2).'), argument('--debug-force-winapi', - default=False, + action='store_true', help='[debug] Forces Windows API.'), argument('--debug-force-fsevents', - default=False, + action='store_true', help='[debug] Forces macOS FSEvents.'), argument('--debug-force-inotify', - default=False, + action='store_true', help='[debug] Forces Linux inotify(7).')], cmd_aliases=['tricks']) def tricks_from(args): @@ -302,7 +303,7 @@ def tricks_from(args): argument('-a', '--append-only', dest='append_only', - default=False, + action='store_true', help=''' If --append-to-file is not specified, produces output for appending instead of a complete tricks YAML file.''')], @@ -357,13 +358,11 @@ def tricks_generate_yaml(args): argument('-D', '--ignore-directories', dest='ignore_directories', - default=False, action='store_true', help='Ignores events for directories.'), argument('-R', '--recursive', dest='recursive', - default=False, action='store_true', help='Monitors the directories recursively.'), argument('--interval', @@ -373,22 +372,22 @@ def tricks_generate_yaml(args): type=float, help='Use this as the polling interval/blocking timeout.'), argument('--trace', - default=False, + action='store_true', help='Dumps complete dispatching trace.'), argument('--debug-force-polling', - default=False, + action='store_true', help='[debug] Forces polling.'), argument('--debug-force-kqueue', - default=False, + action='store_true', help='[debug] Forces BSD kqueue(2).'), argument('--debug-force-winapi', - default=False, + action='store_true', help='[debug] Forces Windows API.'), argument('--debug-force-fsevents', - default=False, + action='store_true', help='[debug] Forces macOS FSEvents.'), argument('--debug-force-inotify', - default=False, + action='store_true', help='[debug] Forces Linux inotify(7).')]) def log(args): """ @@ -472,7 +471,6 @@ def log(args): argument('-R', '--recursive', dest='recursive', - default=False, action='store_true', help='Monitors the directories recursively.'), argument('--interval', @@ -484,16 +482,14 @@ def log(args): argument('-w', '--wait', dest='wait_for_process', action='store_true', - default=False, help='Wait for process to finish to avoid multiple simultaneous instances.'), argument('-W', '--drop', dest='drop_during_process', action='store_true', - default=False, help='Ignore events that occur while command is still being' ' executed to avoid multiple simultaneous instances.'), argument('--debug-force-polling', - default=False, + action='store_true', help='[debug] Forces polling.')]) def shell_command(args): """ @@ -535,7 +531,7 @@ def shell_command(args): argument('-d', '--directory', dest='directories', - metavar='directory', + metavar='DIRECTORY', action='append', help='Directory to watch. Use another -d or --directory option ' 'for each directory.'), @@ -560,7 +556,6 @@ def shell_command(args): argument('-R', '--recursive', dest='recursive', - default=False, action='store_true', help='Monitors the directories recursively.'), argument('--interval', @@ -574,7 +569,7 @@ def shell_command(args): default='SIGINT', help='Stop the subprocess with this signal (default SIGINT).'), argument('--debug-force-polling', - default=False, + action='store_true', help='[debug] Forces polling.'), argument('--kill-after', dest='kill_after', diff --git a/tests/test_0_watchmedo.py b/tests/test_0_watchmedo.py index 5da43146c..36187fcce 100644 --- a/tests/test_0_watchmedo.py +++ b/tests/test_0_watchmedo.py @@ -75,10 +75,12 @@ def test_kill_auto_restart(tmpdir, capfd): def test_auto_restart_arg_parsing_basic(): - args = watchmedo.cli.parse_args(["auto-restart", "-d", ".", "cmd"]) + args = watchmedo.cli.parse_args(["auto-restart", "-d", ".", "--recursive", "--debug-force-polling", "cmd"]) assert args.func is watchmedo.auto_restart assert args.command == "cmd" assert args.directories == ["."] + assert args.recursive + assert args.debug_force_polling def test_auto_restart_arg_parsing_kill_after():