Detect whether a man page's positional args start a nested command. Checks the SYNOPSIS section for a positional argument named 'command'. Excludes angle-bracket patterns like (git subcommand style).
(gz_path: str)
| 92 | |
| 93 | |
| 94 | def detect_nested_cmd(gz_path: str) -> bool: |
| 95 | """Detect whether a man page's positional args start a nested command. |
| 96 | |
| 97 | Checks the SYNOPSIS section for a positional argument named 'command'. |
| 98 | Excludes angle-bracket patterns like <command> (git subcommand style). |
| 99 | """ |
| 100 | try: |
| 101 | with gzip.open(gz_path, "rt", errors="replace") as f: |
| 102 | lines = f.readlines() |
| 103 | except Exception as e: |
| 104 | logger.warning("Failed to read %s for nested_cmd detection: %s", gz_path, e) |
| 105 | return False |
| 106 | |
| 107 | synopsis_lines = _extract_section(lines, "SYNOPSIS") |
| 108 | for line in synopsis_lines: |
| 109 | cleaned = _clean_roff(line) |
| 110 | if not _COMMAND_WORD.search(cleaned): |
| 111 | continue |
| 112 | # Exclude <command> (git-style subcommand pattern) |
| 113 | if _COMMAND_ANGLE.search(cleaned): |
| 114 | continue |
| 115 | # Strip option-name occurrences (e.g. --rsh-command) and recheck |
| 116 | stripped = _COMMAND_IN_OPT.sub("", cleaned) |
| 117 | if _COMMAND_WORD.search(stripped): |
| 118 | logger.debug("nested_cmd: found 'command' in SYNOPSIS of %s", gz_path) |
| 119 | return True |
| 120 | |
| 121 | return False |
nothing calls this directly
no test coverage detected