Skip to content

Commit

Permalink
[watchmedo] Fix broken parsing of commands from auto-restart, and she…
Browse files Browse the repository at this point in the history
…ll-command (#888)

Credit goes to @taleinat!
  • Loading branch information
BoboTiG committed May 13, 2022
1 parent 2830914 commit 3a6eace
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog
- Fix adding failed emitters on observer schedule. (`#872 <https://github.com/gorakhargosh/watchdog/issues/872>`_)
- [watchmedo] Fix broken parsing of ``--kill-after`` argument for the ``auto-restart`` command. (`#870 <https://github.com/gorakhargosh/watchdog/issues/870>`_)
- [watchmedo] Fix broken parsing of boolean arguments. (`#855 <https://github.com/gorakhargosh/watchdog/issues/855>`_)
- [watchmedo] Fix broken parsing of commands from ``auto-restart``, and ``shell-command``. (`#855 <https://github.com/gorakhargosh/watchdog/issues/855>`_)
- Thanks to our beloved contributors: @taleinat, @kianmeng, @palfrey, @IlayRosenberg, @BoboTiG

2.1.7
Expand Down
4 changes: 2 additions & 2 deletions src/watchdog/watchmedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _split_lines(self, text, width):

cli = ArgumentParser(epilog=epilog, formatter_class=HelpFormatter)
cli.add_argument('--version', action='version', version=VERSION_STRING)
subparsers = cli.add_subparsers(dest='command')
subparsers = cli.add_subparsers(dest='top_command')


def argument(*name_or_flags, **kwargs):
Expand Down Expand Up @@ -215,7 +215,7 @@ def schedule_tricks(observer, tricks, pathname, recursive):
argument('--recursive',
action='store_true',
default=True,
help='Recursively monitor paths.'),
help='Recursively monitor paths (defaults to True).'),
argument('--debug-force-polling',
action='store_true',
help='[debug] Forces polling.'),
Expand Down
7 changes: 6 additions & 1 deletion tests/test_0_watchmedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ def test_auto_restart_arg_parsing_basic():
assert args.debug_force_polling


def test_auto_restart_arg_parsing_kill_after():
def test_auto_restart_arg_parsing():
args = watchmedo.cli.parse_args(["auto-restart", "-d", ".", "--kill-after", "12.5", "cmd"])
assert args.func is watchmedo.auto_restart
assert args.command == "cmd"
assert args.directories == ["."]
assert args.kill_after == pytest.approx(12.5)


def test_shell_command_arg_parsing():
args = watchmedo.cli.parse_args(["shell-command", "--command='cmd'"])
assert args.command == "'cmd'"


@pytest.mark.parametrize("command", ["tricks-from", "tricks"])
def test_tricks_from_file(command, tmp_path):
tricks_file = tmp_path / "tricks.yaml"
Expand Down

0 comments on commit 3a6eace

Please sign in to comment.