Skip to content

tldr: env: Add TLDR_PLATFORM env var to override platform detection #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,22 @@ 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
The platform that tldr will use is determined by the `TLDR_PLATFORM` environment variable.
If it is not set, the client will try to determine the platform automatically based on the system it is running on.
The following values are supported:
- `linux`
- `windows`
- `android`
- `freebsd`
- `netbsd`
- `openbsd`
- `osx`
- `sunos`

### 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 <command>` is used.
Expand Down
12 changes: 12 additions & 0 deletions tldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"windows": "windows"
}

SUPPORTED_PLATFORMS = sorted(set(OS_DIRECTORIES.values()))
Copy link
Member

@owenvoke owenvoke Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be using the keys (the platform name), as the values are the actual directories. 👀 Otherwise you won't be able to specify darwin, or win32 👍🏻

Suggested change
SUPPORTED_PLATFORMS = sorted(set(OS_DIRECTORIES.values()))
SUPPORTED_PLATFORMS = sorted(set(OS_DIRECTORIES.keys()))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the idea
As I asked here: #292 (comment)
I have no problem to allow the symlinks

Copy link
Member

@owenvoke owenvoke Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although they don't actually exist in tldr and aren't symlinks, I think it makes sense to support the aliases to be honest as that's the already supported values for --platform on this client (and the Node client).

Or, I guess we can keep it as-is with .values() to stay in-line with --platform on the C client.

I will leave this for someone with more experience in client dev to decide. 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can support it but don't specify this option in the readme.md, agreed ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just say to look at the --platform flag for available platforms, rather than repeating them.



class CacheNotExist(Exception):
pass
Expand Down Expand Up @@ -202,6 +204,16 @@ def update_page_for_platform(


def get_platform() -> str:
platform_env = os.environ.get('TLDR_PLATFORM', '').strip().lower()
if platform_env:
if platform_env in SUPPORTED_PLATFORMS:
return platform_env
else:
print(
f"Warning: '{platform_env}' is not a supported TLDR_PLATFORM env value."
"\nFalling back to auto-detection."
)

for key in OS_DIRECTORIES:
if sys.platform.startswith(key):
return OS_DIRECTORIES[key]
Expand Down