diff --git a/scripts/_common.py b/scripts/_common.py index cac303d442..775b2f6067 100644 --- a/scripts/_common.py +++ b/scripts/_common.py @@ -91,15 +91,15 @@ def test_get_tldr_root(): os.environ["TLDR_ROOT"] = original_env -def get_pages_dir(root: Path) -> list[Path]: +def get_pages_dirs(root: Path) -> list[Path]: """ - Get all pages directories. + Get pages directories for all languages. Parameters: root (Path): the path to search for the pages directories. Returns: - list (list of Path's): Path's of page entry and platform, e.g. "page.fr/common". + list (list of Path's): Path's of all pages directories, e.g. "pages", "pages.fr", "pages.pt_BR", etc. """ return [ @@ -107,7 +107,7 @@ def get_pages_dir(root: Path) -> list[Path]: ] -def test_get_pages_dir(): +def test_get_pages_dirs(): # Create temporary directories with names starting with "pages" root = Path("test_root") @@ -121,7 +121,7 @@ def test_get_pages_dir(): (root / "other_dir_2").mkdir(exist_ok=True) # Call the function and verify that it returns an empty list - result = get_pages_dir(root) + result = get_pages_dirs(root) assert result == [] (root / "pages").mkdir(exist_ok=True) @@ -129,7 +129,7 @@ def test_get_pages_dir(): (root / "other_dir").mkdir(exist_ok=True) # Call the function and verify the result - result = get_pages_dir(root) + result = get_pages_dirs(root) expected = [root / "pages", root / "pages.fr"] assert result.sort() == expected.sort() # the order differs on Unix / macOS @@ -154,10 +154,9 @@ def get_target_paths( if not page.lower().endswith(".md"): page = f"{page}.md" - arg_platform, arg_page = page.split("/") for pages_dir in pages_dirs: - page_path = pages_dir / arg_platform / arg_page + page_path = pages_dir / page if check_exists and not page_path.exists(): print(create_colored_line(Colors.RED, f"Page {page_path} does not exist")) @@ -186,7 +185,7 @@ def test_get_target_paths(): with open(file_path, "w"): pass - target_paths = get_target_paths("common/tldr", get_pages_dir(root)) + target_paths = get_target_paths("common/tldr", get_pages_dirs(root)) for path in target_paths: rel_path = "/".join(path.parts[-3:]) print(rel_path) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index e75c9a9f80..f3e7e3b455 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -54,13 +54,14 @@ Examples: """ import re +import sys from pathlib import Path from dataclasses import dataclass from _common import ( IGNORE_FILES, Colors, get_tldr_root, - get_pages_dir, + get_pages_dirs, get_target_paths, get_locale, get_status, @@ -454,8 +455,14 @@ def main(): "Sets the alias page for all translations of a page" ) args = parser.parse_args() + + # Print usage information if no arguments were provided + if len(sys.argv) == 1: + parser.print_help() + return + root = get_tldr_root() - pages_dirs = get_pages_dir(root) + pages_dirs = get_pages_dirs(root) templates = get_templates(root) global config diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 24ffbc6944..676ce9eb4f 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -48,12 +48,13 @@ Examples: """ import re +import sys from pathlib import Path from _common import ( IGNORE_FILES, Colors, get_tldr_root, - get_pages_dir, + get_pages_dirs, get_target_paths, get_locale, get_status, @@ -253,8 +254,13 @@ def main(): parser.add_argument("link", type=str, nargs="?", default="") args = parser.parse_args() + # Print usage information if no arguments were provided + if len(sys.argv) == 1: + parser.print_help() + return + root = get_tldr_root() - pages_dirs = get_pages_dir(root) + pages_dirs = get_pages_dirs(root) target_paths = [] diff --git a/scripts/set-page-title.py b/scripts/set-page-title.py index 3476a2ed3d..6945822d1b 100755 --- a/scripts/set-page-title.py +++ b/scripts/set-page-title.py @@ -47,12 +47,13 @@ Examples: python3 scripts/set-page-title.py --sync --dry-run """ +import sys from pathlib import Path from _common import ( IGNORE_FILES, Colors, get_tldr_root, - get_pages_dir, + get_pages_dirs, get_target_paths, get_locale, get_status, @@ -167,8 +168,13 @@ def main(): parser.add_argument("title", type=str, nargs="?", default="") args = parser.parse_args() + # Print usage information if no arguments were provided + if len(sys.argv) == 1: + parser.print_help() + return + root = get_tldr_root() - pages_dirs = get_pages_dir(root) + pages_dirs = get_pages_dirs(root) target_paths = []