Skip to content

Commit f27e5c0

Browse files
committed
Keep CLI parser clean
1 parent dfdfd33 commit f27e5c0

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

slide2vec/cli.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ def get_args_parser(add_help: bool = True):
1717

1818
def parse_args(argv=None):
1919
parser = get_args_parser(add_help=True)
20-
if hasattr(parser, "parse_known_args"):
21-
args, opts = parser.parse_known_args(argv)
22-
args.opts = opts
23-
else:
24-
args = parser.parse_args(argv)
25-
args.opts = getattr(args, "opts", [])
20+
args, opts = parser.parse_known_args(argv)
21+
args.opts = opts
2622
return args
2723

2824

tasks/lessons.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 2026-04-12
44

5-
- When refactoring CLI parsing to support `parse_known_args()`, keep existing test doubles in mind: if a fake parser only implements `parse_args()`, add a small compatibility fallback instead of forcing every monkeypatch to mirror the full parser API.
5+
- When refactoring CLI parsing to support `parse_known_args()`, prefer updating the test double to match the real parser API instead of adding a production fallback for mocks. Keep the runtime code clean unless the fallback is genuinely needed by real callers.
66

77
## 2026-04-10
88

tests/test_progress.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class FakeParser:
112112
def parse_args(self, argv=None):
113113
return SimpleNamespace(tiling_only=False)
114114

115+
def parse_known_args(self, argv=None):
116+
return self.parse_args(argv), []
117+
115118
monkeypatch.setattr(cli, "get_args_parser", lambda add_help=True: FakeParser())
116119
monkeypatch.setattr(
117120
cli,

0 commit comments

Comments
 (0)