From aa2087f1cd32192c15a340100bab000371c0adcc Mon Sep 17 00:00:00 2001 From: Kausheya2006 Date: Wed, 1 Oct 2025 13:17:23 +0530 Subject: [PATCH] Added new flag : -x to list commands exclusive to a platform --- README.md | 1 + tldr.py | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea0fdc9..97f8244 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ options: -p PLATFORM, --platform PLATFORM Override the operating system [android, freebsd, linux, netbsd, openbsd, osx, sunos, windows, common] -l, --list List all available commands for operating system + -x, --exclusive Use with --list and -p to list commands exclusive to the specfied platform -s SOURCE, --source SOURCE Override the default page source -c, --color Override color stripping diff --git a/tldr.py b/tldr.py index fb81560..35233a3 100755 --- a/tldr.py +++ b/tldr.py @@ -382,9 +382,21 @@ def get_page( COMMAND_SPLIT_REGEX = re.compile(r'(?P{{.+?}*}})') PARAM_REGEX = re.compile(r'(?:{{)(?P.+?)(?:}})') +def get_exclusive_commands(platforms: List[str], language: Optional[List[str]] = None) -> List[str]: + + common_commands = set(get_commands(['common'], language)) + exclusive_commands = set() + + for platform in platforms: + platform_commands = set(get_commands([platform], language)) + exclusive_commands.update(platform_commands - common_commands) + + return sorted(exclusive_commands) + def get_commands(platforms: Optional[List[str]] = None, - language: Optional[str] = None) -> List[str]: + language: Optional[str] = None, + exclusive: bool = False) -> List[str]: if platforms is None: platforms = get_platform_list() @@ -394,6 +406,10 @@ def get_commands(platforms: Optional[List[str]] = None, languages = get_language_list() commands = [] + + if exclusive: + return get_exclusive_commands(platforms, language); + if get_cache_dir().exists(): for platform in platforms: for language in languages: @@ -610,6 +626,11 @@ def create_parser() -> ArgumentParser: action='store_true', help="List all available commands for operating system") + parser.add_argument('-x', '--exclusive', + default=False, + action='store_true', + help="Use with --list and -p to list commands exclusive to the specfied platform") + parser.add_argument('-s', '--source', default=PAGES_SOURCE_LOCATION, type=str, @@ -714,7 +735,8 @@ def main() -> None: parser.print_help(sys.stderr) sys.exit(1) if options.list: - print('\n'.join(get_commands(options.platform, options.language))) + print('\n'.join(get_commands(options.platform, options.language, options.exclusive))) + elif options.render: for command in options.command: file_path = Path(command)