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.
This commit is contained in:
parent
e50fc9444a
commit
1ea149c1de
2 changed files with 23 additions and 2 deletions
|
|
@ -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",
|
||||
|
|
|
|||
14
topen.py
14
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue