(
ctx: click.Context, command: click.Command, parent_name: str | None = None
)
| 180 | |
| 181 | |
| 182 | def generate_command_help( |
| 183 | ctx: click.Context, command: click.Command, parent_name: str | None = None |
| 184 | ) -> StrGenerator: |
| 185 | # TODO: Add references to long options. Requires splitting out examples. |
| 186 | # TODO: Add references to subcommands. Need to add actual refs, since programs can't be ref'd. |
| 187 | # TODO: Handle dollar signs in examples by having both escaped and unescaped versions |
| 188 | yield f"\n.. _command-{command.name}:\n" |
| 189 | yield "\n.. program:: %s\n\n" % ( |
| 190 | command.name if parent_name is None else f"{parent_name} {command.name}" |
| 191 | ) |
| 192 | if parent_name: |
| 193 | yield from generate_title(f"``{command.name}``", 1) |
| 194 | |
| 195 | replacements = [ |
| 196 | opt |
| 197 | for opts in [param.opts for param in command.params if hasattr(param, "opts")] |
| 198 | for opt in opts |
| 199 | ] |
| 200 | |
| 201 | help = command.help |
| 202 | help = help.replace( |
| 203 | "Examples:\n", "".join(generate_title("Examples", 0 if not parent_name else 2)) |
| 204 | ) |
| 205 | help = help.replace("\b\n", "") |
| 206 | help = help.format(scenedetect="scenedetect", scenedetect_with_video="scenedetect -i video.mp4") |
| 207 | help = transform_backquotes(help) |
| 208 | help = transform_add_option_refs(help, replacements) |
| 209 | |
| 210 | for line in help.strip().splitlines(): |
| 211 | if line.startswith(INDENT): |
| 212 | indent = line.count(INDENT) |
| 213 | line = line.strip() |
| 214 | yield f"{indent * INDENT}``{line}``\n" if line else "\n" |
| 215 | else: |
| 216 | yield f"{line}\n" |
| 217 | |
| 218 | if command.params: |
| 219 | yield "\n" |
| 220 | yield from generate_title("Options", 0 if not parent_name else 2) |
| 221 | for param in command.params: |
| 222 | yield from format_option(command, param, replacements) |
| 223 | yield "\n" |
| 224 | |
| 225 | |
| 226 | def generate_subcommands(ctx: click.Context, commands: list[str]) -> StrGenerator: |
no test coverage detected