Skip to content

Commit 56ddf2e

Browse files
Kasper JungeRalphify
authored andcommitted
fix: treat null command timeout as default instead of erroring
When a RALPH.md command had `timeout:` (no value) or `timeout: null`, dict.get() returned None instead of the default because the key existed. This caused _is_valid_timeout(None) to fail with a confusing error. Now explicitly checks for None before validation, consistent with how commands, args, and credit fields already handle null values. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 120b3c2 commit 56ddf2e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/ralphify/cli.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ralphify import __version__
2222
from ralphify import _brand
2323
from ralphify._console_emitter import ConsoleEmitter
24+
from ralphify._keypress import KeypressListener
2425
from ralphify._frontmatter import (
2526
CMD_FIELD_NAME,
2627
CMD_FIELD_RUN,
@@ -307,7 +308,9 @@ def _parse_command_items(raw_commands: list[dict[str, Any]]) -> list[Command]:
307308
if cmd_name in seen_names:
308309
_exit_error(f"Duplicate command name '{cmd_name}'.")
309310
seen_names.add(cmd_name)
310-
timeout = cmd_def.get(CMD_FIELD_TIMEOUT, DEFAULT_COMMAND_TIMEOUT)
311+
timeout = cmd_def.get(CMD_FIELD_TIMEOUT)
312+
if timeout is None:
313+
timeout = DEFAULT_COMMAND_TIMEOUT
311314
if not _is_valid_timeout(timeout):
312315
_exit_error(
313316
f"Command '{cmd_name}' has invalid timeout: {timeout!r}. "
@@ -556,7 +559,15 @@ def _sigint_handler(signum: int, frame: Any) -> None:
556559
raise KeyboardInterrupt
557560

558561
signal.signal(signal.SIGINT, _sigint_handler)
562+
563+
def _on_key(key: str) -> None:
564+
if key == "p":
565+
emitter.toggle_peek()
566+
567+
listener = KeypressListener(_on_key)
568+
listener.start()
559569
try:
560570
run_loop(config, state, emitter)
561571
finally:
572+
listener.stop()
562573
signal.signal(signal.SIGINT, original_handler)

tests/test_cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,15 @@ def test_default_timeout(self):
737737
commands = _parse_command_items(raw)
738738
assert commands[0].timeout == DEFAULT_COMMAND_TIMEOUT
739739

740+
def test_null_timeout_uses_default(self):
741+
"""YAML `timeout:` (no value) or `timeout: null` should use the default timeout,
742+
not error — consistent with how commands/args/credit treat null values."""
743+
from ralphify._run_types import DEFAULT_COMMAND_TIMEOUT
744+
745+
raw = [{"name": "test", "run": "echo hi", "timeout": None}]
746+
commands = _parse_command_items(raw)
747+
assert commands[0].timeout == DEFAULT_COMMAND_TIMEOUT
748+
740749
def test_missing_name_errors(self):
741750
with pytest.raises(typer.Exit):
742751
_parse_command_items([{"run": "echo hi"}])

0 commit comments

Comments
 (0)