|
56 | 56 | "osx": "osx",
|
57 | 57 | "sunos": "sunos",
|
58 | 58 | "win32": "windows",
|
59 |
| - "windows": "windows" |
| 59 | + "windows": "windows", |
| 60 | + "common": "common", |
60 | 61 | }
|
61 | 62 |
|
62 |
| -SUPPORTED_PLATFORMS = sorted(set(OS_DIRECTORIES.values())) |
63 |
| - |
64 |
| - |
65 | 63 | class CacheNotExist(Exception):
|
66 | 64 | pass
|
67 | 65 |
|
@@ -204,24 +202,14 @@ def update_page_for_platform(
|
204 | 202 |
|
205 | 203 |
|
206 | 204 | 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 |
| - |
217 | 205 | for key in OS_DIRECTORIES:
|
218 | 206 | if sys.platform.startswith(key):
|
219 | 207 | return OS_DIRECTORIES[key]
|
220 | 208 | return 'linux'
|
221 | 209 |
|
222 | 210 |
|
223 | 211 | def get_platform_list() -> List[str]:
|
224 |
| - platforms = ['common'] + list(set(OS_DIRECTORIES.values())) |
| 212 | + platforms = list(set(OS_DIRECTORIES.values())) |
225 | 213 | current_platform = get_platform()
|
226 | 214 | platforms.remove(current_platform)
|
227 | 215 | platforms.insert(0, current_platform)
|
@@ -681,6 +669,17 @@ def main() -> None:
|
681 | 669 |
|
682 | 670 | options = parser.parse_args()
|
683 | 671 |
|
| 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 | + |
684 | 683 | display_option_length = "long"
|
685 | 684 | if os.environ.get('TLDR_OPTIONS') == "short":
|
686 | 685 | display_option_length = "short"
|
|
0 commit comments