Skip to content

Commit 0430d34

Browse files
author
Itamar Shalev
committed
env: Use env platform if --platform wasn't given
Signed-off-by: Itamar Shalev <[email protected]>
1 parent 080137c commit 0430d34

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,8 @@ export TLDR_PLATFORM=linux
9595
```
9696
9797
### Platform
98-
The platform that tldr will use is determined by the `TLDR_PLATFORM` environment variable.
99-
If it is not set, the client will try to determine the platform automatically based on the system it is running on.
100-
The following values are supported:
101-
- `linux`
102-
- `windows`
103-
- `android`
104-
- `freebsd`
105-
- `netbsd`
106-
- `openbsd`
107-
- `osx`
108-
- `sunos`
98+
Determines the platform that tldr will use based on the `TLDR_PLATFORM` environment variable or system detection.
99+
For a complete list of supported platform values, refer to the help for the `--platform` option flag.
109100
110101
### Cache
111102

tldr.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@
5656
"osx": "osx",
5757
"sunos": "sunos",
5858
"win32": "windows",
59-
"windows": "windows"
59+
"windows": "windows",
60+
"common": "common",
6061
}
6162

62-
SUPPORTED_PLATFORMS = sorted(set(OS_DIRECTORIES.values()))
63-
64-
6563
class CacheNotExist(Exception):
6664
pass
6765

@@ -204,24 +202,14 @@ def update_page_for_platform(
204202

205203

206204
def get_platform() -> str:
207-
platform_env = os.environ.get('TLDR_PLATFORM', '').strip().lower()
208-
if platform_env:
209-
if platform_env in SUPPORTED_PLATFORMS:
210-
return platform_env
211-
else:
212-
print(
213-
f"Warning: '{platform_env}' is not a supported TLDR_PLATFORM env value."
214-
"\nFalling back to auto-detection."
215-
)
216-
217205
for key in OS_DIRECTORIES:
218206
if sys.platform.startswith(key):
219207
return OS_DIRECTORIES[key]
220208
return 'linux'
221209

222210

223211
def get_platform_list() -> List[str]:
224-
platforms = ['common'] + list(set(OS_DIRECTORIES.values()))
212+
platforms = list(set(OS_DIRECTORIES.values()))
225213
current_platform = get_platform()
226214
platforms.remove(current_platform)
227215
platforms.insert(0, current_platform)
@@ -681,6 +669,17 @@ def main() -> None:
681669

682670
options = parser.parse_args()
683671

672+
673+
if options.platform is None:
674+
platform_env = os.environ.get('TLDR_PLATFORM', '').strip().lower()
675+
if platform_env in OS_DIRECTORIES:
676+
options.platform = [platform_env]
677+
elif platform_env:
678+
print(
679+
f"Warning: '{platform_env}' is not a supported TLDR_PLATFORM env value."
680+
"\nFalling back to auto-detection."
681+
)
682+
684683
display_option_length = "long"
685684
if os.environ.get('TLDR_OPTIONS') == "short":
686685
display_option_length = "short"

0 commit comments

Comments
 (0)