import re from pathlib import Path from unshackle.commands.dl import dl CLI_REFERENCE = Path(__file__).parents[2] / "docs" / "guide" / "cli-reference.md" def dl_section_flags() -> set[str]: """The flags that start a code span in the `dl` section of the CLI reference.""" text = CLI_REFERENCE.read_text(encoding="utf-8") start = text.index("## `dl`") section = text[start : text.index("\n## ", start)] return set(re.findall(r"`(--?[a-zA-Z][\w-]*)", section)) def dl_option_flags() -> set[str]: return { flag for param in dl.cli.params if param.param_type_name == "option" and not param.hidden for flag in (*param.opts, *param.secondary_opts) } def test_every_dl_option_is_in_the_cli_reference() -> None: assert dl_option_flags() - dl_section_flags() == set() def test_every_long_flag_in_the_cli_reference_is_a_dl_option() -> None: assert {flag for flag in dl_section_flags() if flag.startswith("--")} - dl_option_flags() == set()