Skip to content

Commit

Permalink
update cli
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee committed Apr 12, 2023
1 parent 38f27b6 commit 3953c73
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/cli_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ usage: watchfiles [-h] [--ignore-paths [IGNORE_PATHS]]
[--filter [FILTER]] [--args [ARGS]] [--verbose]
[--non-recursive] [--verbosity [{warning,info,debug}]]
[--sigint-timeout [SIGINT_TIMEOUT]]
[--sigkill-timeout [SIGKILL_TIMEOUT]] [--version]
[--sigkill-timeout [SIGKILL_TIMEOUT]]
[--ignore-permission-denied] [--version]
target [paths ...]

Watch one or more directories and execute either a shell command or a python function on file changes.
Expand Down Expand Up @@ -38,4 +39,6 @@ options:
How long to wait for the sigint timeout before sending sigkill.
--sigkill-timeout [SIGKILL_TIMEOUT]
How long to wait for the sigkill timeout before issuing a timeout exception.
--ignore-permission-denied
Ignore permission denied errors while watching files and directories.
--version, -V show program's version number and exit
11 changes: 11 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_function(mocker, tmp_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand Down Expand Up @@ -52,6 +53,7 @@ def test_ignore_paths(mocker, tmp_work_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand Down Expand Up @@ -105,6 +107,7 @@ def test_command(mocker, tmp_work_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand All @@ -122,6 +125,7 @@ def test_verbosity(mocker, tmp_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand All @@ -139,6 +143,7 @@ def test_verbose(mocker, tmp_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand All @@ -156,6 +161,7 @@ def test_non_recursive(mocker, tmp_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=False,
ignore_permission_denied=False,
)


Expand All @@ -173,6 +179,7 @@ def test_filter_all(mocker, tmp_path, capsys):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)
out, err = capsys.readouterr()
assert out == ''
Expand All @@ -193,6 +200,7 @@ def test_filter_default(mocker, tmp_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand All @@ -210,6 +218,7 @@ def test_set_type(mocker, tmp_path):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)


Expand Down Expand Up @@ -265,6 +274,7 @@ def test_args(mocker, tmp_path, reset_argv, caplog):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)
assert sys.argv == ['os.getcwd', '--version']
assert 'WARNING: --args' not in caplog.text
Expand All @@ -286,5 +296,6 @@ def test_args_command(mocker, tmp_path, caplog):
sigint_timeout=5,
sigkill_timeout=1,
recursive=True,
ignore_permission_denied=False,
)
assert 'WARNING: --args is only used when the target is a function\n' in caplog.text
3 changes: 3 additions & 0 deletions tests/test_rust_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,6 @@ def test_polling_repr(test_dir: Path):
@skip_windows
def test_ignore_permission_denied():
RustNotify(['/'], False, False, 0, True, True)

with pytest.raises(PermissionError):
RustNotify(['/'], False, False, 0, True, False)
1 change: 1 addition & 0 deletions watchfiles/_rust_notify.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RustNotify:
poll_delay_ms: delay between polling for changes, only used if `force_polling=True`
recursive: if `True`, watch for changes in sub-directories recursively, otherwise watch only for changes in
the top-level directory, default is `True`.
ignore_permission_denied: if `True`, permission denied errors are ignored while watching changes.
"""
def watch(
self,
Expand Down
6 changes: 6 additions & 0 deletions watchfiles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def cli(*args_: str) -> None:
default=1,
help='How long to wait for the sigkill timeout before issuing a timeout exception.',
)
parser.add_argument(
'--ignore-permission-denied',
action='store_true',
help='Ignore permission denied errors while watching directories.',
)
parser.add_argument('--version', '-V', action='version', version=f'%(prog)s v{VERSION}')
arg_namespace = parser.parse_args(args)

Expand Down Expand Up @@ -165,6 +170,7 @@ def cli(*args_: str) -> None:
sigint_timeout=arg_namespace.sigint_timeout,
sigkill_timeout=arg_namespace.sigkill_timeout,
recursive=not arg_namespace.non_recursive,
ignore_permission_denied=arg_namespace.ignore_permission_denied,
)


Expand Down

0 comments on commit 3953c73

Please sign in to comment.