From 1ea149c1de1908cc0005e57fe33d20b907f68b51 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 29 Nov 2025 11:18:48 +0100 Subject: [PATCH] fix: Ensure quiet is a flag on the cli We regressed quiet into requiring a value to be set as a cli option (`--quiet=true`) instead of just functioning as a flag (`--quiet`). This change restores the previous interface on the command line, and adds a test to ensure no regressions. --- test/test_parse_cli.py | 11 +++++++++++ topen.py | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/test_parse_cli.py b/test/test_parse_cli.py index 409ca8e..984dcf5 100644 --- a/test/test_parse_cli.py +++ b/test/test_parse_cli.py @@ -29,6 +29,17 @@ class TestCli: "notes_annot": "HERENOTE", } + def test_cli_notes_quiet_is_flag(self, monkeypatch): + monkeypatch.setattr( + "sys.argv", + [ + "topen", + "123", + "--quiet", + ], + ) + assert parse_cli()["notes_quiet"] is True + def test_cli_parses_paths(self, monkeypatch): monkeypatch.setattr( "sys.argv", diff --git a/topen.py b/topen.py index 0143907..e04e39e 100755 --- a/topen.py +++ b/topen.py @@ -132,7 +132,7 @@ class Opt: metavar: str | None = None cast: type | Callable = str help_text: str = "" - flag: bool = False + is_flag: bool = False def _real_path(p: Path | str) -> Path: @@ -224,7 +224,8 @@ OPTIONS: dict[str, Opt] = { "notes.quiet", default=False, cast=_strtobool, - help_text="Silence any verbose displayed information", + help_text="Silence any verbosely displayed information", + is_flag=True, ), } @@ -321,6 +322,15 @@ you view the task. for key, opt in OPTIONS.items(): if opt.cli is None: continue + if opt.is_flag: + parser.add_argument( + *opt.cli, + dest=key, + help=opt.help_text, + default=None, + action="store_true", + ) + continue parser.add_argument( *opt.cli, dest=key,