66
77import sys
88from io import StringIO
9+ from operator import itemgetter
910
1011from rich .console import Console
1112
@@ -35,6 +36,19 @@ def _capture_help(args: list[str]) -> str:
3536 sys .stdout = old_stdout
3637
3738
39+ def _is_outdated (check : tuple [str , list [str ], str ]) -> bool :
40+ """Return True if the current help output differs from the stored constant."""
41+ _ , args , current = check
42+ return _capture_help (args ) != current
43+
44+
45+ def _find_outdated_checks (
46+ checks : list [tuple [str , list [str ], str ]],
47+ ) -> list [tuple [str , list [str ]]]:
48+ """Return checks whose current help output differs from the stored constant."""
49+ return list (map (itemgetter (0 , 1 ), filter (_is_outdated , checks )))
50+
51+
3852def _as_constant_snippet (name : str , text : str ) -> str :
3953 """Return a copy-pasteable constant assignment for *text*."""
4054 lines = text .splitlines ()
@@ -47,9 +61,7 @@ def _as_constant_snippet(name: str, text: str) -> str:
4761 ("_HELP_PAGE" , ["--help" ], _HELP_PAGE ),
4862 ("_BUILD_HELP_PAGE" , ["build" , "--help" ], _BUILD_HELP_PAGE ),
4963 ]
50- changed = [
51- (name , args ) for name , args , current in checks if _capture_help (args ) != current
52- ]
64+ changed = _find_outdated_checks (checks )
5365
5466 if not changed :
5567 print ("No changes detected. All help-output constants are up to date." )
0 commit comments