From 3b69fd6e97430a282489872aa02462ef9cf5fca3 Mon Sep 17 00:00:00 2001 From: Lily Dayton Date: Sun, 22 Mar 2026 21:22:11 +0200 Subject: [PATCH 1/2] Add --help, --version, and TTY detection to CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running dippy with no stdin no longer hangs — it detects the TTY and prints a hint. --help/-h shows usage, --version/-V prints the version. All checked before reading stdin. Closes #100 --- src/dippy/dippy.py | 33 +++++++++++++++++++++++ tests/test_dippy.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/src/dippy/dippy.py b/src/dippy/dippy.py index dc76408..eb069da 100644 --- a/src/dippy/dippy.py +++ b/src/dippy/dippy.py @@ -271,6 +271,39 @@ def main(): """Main entry point for the hook.""" global MODE + # Early exit flags — checked before reading stdin + if "--help" in sys.argv or "-h" in sys.argv: + from dippy import __version__ + + print(f"Dippy v{__version__} — approval autopilot for AI coding assistants") + print() + print("Usage: dippy [--claude|--gemini|--cursor]") + print() + print("Reads JSON hook payload from stdin. Outputs a JSON decision.") + print() + print("Modes:") + print(" --claude Force Claude Code mode") + print(" --gemini Force Gemini CLI mode") + print(" --cursor Force Cursor mode") + print(" (auto-detected from input if not specified)") + print() + print("Flags:") + print(" --help, -h Show this help") + print(" --version, -V Show version") + raise SystemExit(0) + + if "--version" in sys.argv or "-V" in sys.argv: + from dippy import __version__ + + print(f"dippy {__version__}") + raise SystemExit(0) + + # If stdin is a TTY, no input is being piped — show help instead of hanging + if sys.stdin.isatty(): + print("dippy: no input (expected JSON on stdin)") + print("Run 'dippy --help' for usage.") + raise SystemExit(0) + setup_logging() try: diff --git a/tests/test_dippy.py b/tests/test_dippy.py index 42edb4b..cd8136a 100644 --- a/tests/test_dippy.py +++ b/tests/test_dippy.py @@ -3966,6 +3966,70 @@ def test_command(check, cmd, expected_safe): assert needs_confirmation(result), f"Expected confirmation for: {cmd}" +class TestCLI: + """Test CLI flags (--help, --version) and TTY detection.""" + + def test_help_flag(self, capsys): + import sys + from unittest.mock import patch + + with patch.object(sys, "argv", ["dippy", "--help"]): + from dippy.dippy import main + + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 0 + captured = capsys.readouterr() + assert "Usage:" in captured.out + assert "--claude" in captured.out + + def test_help_flag_short(self, capsys): + import sys + from unittest.mock import patch + + with patch.object(sys, "argv", ["dippy", "-h"]): + from dippy.dippy import main + + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 0 + captured = capsys.readouterr() + assert "Usage:" in captured.out + + def test_version_flag(self, capsys): + import sys + from unittest.mock import patch + + with patch.object(sys, "argv", ["dippy", "--version"]): + from dippy.dippy import main + + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 0 + captured = capsys.readouterr() + from dippy import __version__ + + assert __version__ in captured.out + + def test_tty_shows_help(self, capsys): + """When stdin is a TTY (no piped input), show help instead of hanging.""" + import sys + from unittest.mock import patch + + with ( + patch.object(sys, "argv", ["dippy"]), + patch.object(sys.stdin, "isatty", return_value=True), + ): + from dippy.dippy import main + + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 0 + captured = capsys.readouterr() + assert "no input" in captured.out + assert "--help" in captured.out + + class TestPostToolUse: """Test PostToolUse hook handling.""" From f0178c322d5e5a9d0bb2fefd5fd6add841c92ad1 Mon Sep 17 00:00:00 2001 From: Lily Dayton Date: Sun, 22 Mar 2026 21:25:18 +0200 Subject: [PATCH 2/2] Fix Python 3.8 compat: avoid parenthesized context managers --- tests/test_dippy.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_dippy.py b/tests/test_dippy.py index cd8136a..db17bde 100644 --- a/tests/test_dippy.py +++ b/tests/test_dippy.py @@ -4016,9 +4016,8 @@ def test_tty_shows_help(self, capsys): import sys from unittest.mock import patch - with ( - patch.object(sys, "argv", ["dippy"]), - patch.object(sys.stdin, "isatty", return_value=True), + with patch.object(sys, "argv", ["dippy"]), patch.object( + sys.stdin, "isatty", return_value=True ): from dippy.dippy import main