diff --git a/concore_cli/cli.py b/concore_cli/cli.py index 4b376c9..c3ef2f3 100644 --- a/concore_cli/cli.py +++ b/concore_cli/cli.py @@ -167,6 +167,9 @@ def stop(): @click.option("--once", is_flag=True, help="Print a single snapshot and exit") def watch(study_dir, interval, once): """Watch a running simulation study for live monitoring""" + if interval <= 0: + console.print("[red]Error:[/red] --interval must be greater than 0") + sys.exit(1) try: watch_study(study_dir, interval, once, console) except Exception as e: diff --git a/tests/test_cli.py b/tests/test_cli.py index d746040..8f4506a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -786,6 +786,24 @@ def test_inspect_missing_source_file(self): self.assertEqual(result.exit_code, 0) self.assertIn("Missing files", result.output) + def test_watch_rejects_negative_interval(self): + with self.runner.isolated_filesystem(temp_dir=self.temp_dir): + os.mkdir("study") + result = self.runner.invoke( + cli, ["watch", "study", "--interval", "-1"] + ) + self.assertEqual(result.exit_code, 1) + self.assertIn("--interval must be greater than 0", result.output) + + def test_watch_rejects_zero_interval(self): + with self.runner.isolated_filesystem(temp_dir=self.temp_dir): + os.mkdir("study") + result = self.runner.invoke( + cli, ["watch", "study", "--interval", "0"] + ) + self.assertEqual(result.exit_code, 1) + self.assertIn("--interval must be greater than 0", result.output) + if __name__ == "__main__": unittest.main()