diff --git a/README.md b/README.md index 53a87ba..f678337 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,13 @@ export TLDR_CACHE_MAX_AGE=720 export TLDR_PAGES_SOURCE_LOCATION="https://raw.githubusercontent.com/tldr-pages/tldr/main/pages" export TLDR_DOWNLOAD_CACHE_LOCATION="https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip" export TLDR_OPTIONS=short +export TLDR_PLATFORM=linux ``` +### Platform +Determines the platform that tldr will use based on the `TLDR_PLATFORM` environment variable or system detection. +For a complete list of supported platform values, refer to the help for the `--platform` option flag. + ### Cache Cache is downloaded from `TLDR_DOWNLOAD_CACHE_LOCATION` (defaults to the one described in [the client specification](https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#caching)), unzipped and extracted into the [local cache directory](#cache-location). Pages are loaded directly from `TLDR_PAGES_SOURCE_LOCATION` if `tldr ` is used. diff --git a/tldr.py b/tldr.py index 161e960..852f9ad 100755 --- a/tldr.py +++ b/tldr.py @@ -56,7 +56,8 @@ "osx": "osx", "sunos": "sunos", "win32": "windows", - "windows": "windows" + "windows": "windows", + "common": "common", } @@ -209,7 +210,7 @@ def get_platform() -> str: def get_platform_list() -> List[str]: - platforms = ['common'] + list(set(OS_DIRECTORIES.values())) + platforms = list(set(OS_DIRECTORIES.values())) current_platform = get_platform() platforms.remove(current_platform) platforms.insert(0, current_platform) @@ -592,17 +593,17 @@ def create_parser() -> ArgumentParser: action='store_true', help="Delete the local cache of pages and exit") + all_platforms = sorted(set(OS_DIRECTORIES.values())) + platforms_str = "[" + ", ".join(all_platforms) + "]" + parser.add_argument( '-p', '--platform', nargs=1, default=None, type=str, - choices=['android', 'freebsd', 'linux', 'netbsd', 'openbsd', 'osx', 'sunos', - 'windows', 'common'], + choices=all_platforms, metavar='PLATFORM', - help="Override the operating system " - "[android, freebsd, linux, netbsd, openbsd," - " osx, sunos, windows, common]" + help=f"Override the operating system {platforms_str}" ) parser.add_argument('-l', '--list', @@ -669,6 +670,16 @@ def main() -> None: options = parser.parse_args() + if options.platform is None: + platform_env = os.environ.get('TLDR_PLATFORM', '').strip().lower() + if platform_env in OS_DIRECTORIES: + options.platform = [platform_env] + elif platform_env: + print( + f"Warning: '{platform_env}' is not a supported TLDR_PLATFORM env value." + "\nFalling back to auto-detection." + ) + display_option_length = "long" if os.environ.get('TLDR_OPTIONS') == "short": display_option_length = "short"