Skip to content

Commit b87259f

Browse files
committed
refactor(export): move ready/exit hint to shell wrappers
Drop --exit-hint from tos.py hello and let each shell script print its own ready line and exit hint, so PowerShell can advise `deactivate` only while cmd/bash keep the `exit` or `deactivate` wording. Made-with: Cursor
1 parent e4b41fa commit b87259f

4 files changed

Lines changed: 18 additions & 34 deletions

File tree

export.bat

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ if exist "%CACHE_PATH%\.dont_prompt_update_platform" del /F /Q "%CACHE_PATH%\.do
168168
:: sees inside the fresh child cmd is:
169169
:: OPEN_SDK_ROOT / Host / [TuyaOpen] Note banner
170170
:: [INFO]: Running tos.py ... (from tos.py hello)
171-
:: ASCII art + "ready" / exit hint
171+
:: ASCII art, then "ready" / exit lines from this script
172172
:: i.e. environment info FIRST, greeting SECOND. Running hello in the
173173
:: parent here would print it above the child's "Microsoft Windows ..."
174174
:: header and scroll away before the user could read the banner.
@@ -182,6 +182,8 @@ if exist "%CACHE_PATH%\.dont_prompt_update_platform" del /F /Q "%CACHE_PATH%\.do
182182
:: ---------------------------------------------------------------------------
183183
if not "%IS_RESOURCE%"=="1" goto :spawn_child
184184
"%OPEN_SDK_PYTHON%" "%OPEN_SDK_ROOT%\tos.py" hello
185+
echo tos.py Tool and TuyaOpen SDK is now ready.
186+
echo Exit environment: `exit` or `deactivate`.
185187
goto :eof
186188

187189
:spawn_child
@@ -239,10 +241,12 @@ if "%PY_IN_RANGE%"=="0" >>"%TUYA_ALIAS_BAT%" echo echo [TuyaOpen] Warning: Pytho
239241
if "%PY_IN_RANGE%"=="1" if not "%PY_MINOR%"=="11" >>"%TUYA_ALIAS_BAT%" echo echo [TuyaOpen] Note: Python 3.11 is recommended; 3.9 - 3.13 are supported ^^^(detected 3.%PY_MINOR%^^^).
240242

241243
:: Run tos.py hello AFTER the banner so the visible order in the child cmd is
242-
:: "environment info -> [INFO]: Running tos.py ... -> ASCII art -> ready hint".
244+
:: "environment info -> [INFO]: Running tos.py ... -> ASCII art -> ready/exit".
243245
:: Invoked in the child (not the parent) so it appears below the banner
244246
:: instead of scrolling off behind the child cmd's own header.
245247
>>"%TUYA_ALIAS_BAT%" echo "%OPEN_SDK_PYTHON%" "%OPEN_SDK_ROOT%\tos.py" hello
248+
>>"%TUYA_ALIAS_BAT%" echo echo tos.py Tool and TuyaOpen SDK is now ready.
249+
>>"%TUYA_ALIAS_BAT%" echo echo Exit environment: `exit` or `deactivate`.
246250

247251
cmd /d /k "%TUYA_ALIAS_BAT%"
248252

export.ps1

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,12 @@ function global:prompt {
287287
}
288288

289289
# ---------------------------------------------------------------------------
290-
# Greeting banner (via tos.py hello; prints TuyaOpen version inside the art).
291-
#
292-
# `exit` is a PowerShell *language keyword*, not a cmdlet, so a function
293-
# named `exit` cannot shadow it. The default hint line from `tos.py hello`
294-
# ("Exit environment: `exit` or `deactivate`.") is therefore misleading in
295-
# a PS shell - typing `exit` would close the caller's terminal rather than
296-
# just leaving the TuyaOpen env. Suppress the default and print a
297-
# PS-specific single-command hint (`deactivate` only) instead.
290+
# Greeting banner (via tos.py hello; ASCII/version only). "Ready" + exit hint
291+
# are printed here so PowerShell can recommend `deactivate` only — `exit` is
292+
# a language keyword and cannot be wrapped like in cmd/bash.
298293
# ---------------------------------------------------------------------------
299-
& $pythonExe (Join-Path $OpenSdkRoot 'tos.py') hello --exit-hint ''
294+
& $pythonExe (Join-Path $OpenSdkRoot 'tos.py') hello
295+
Write-Host 'tos.py Tool and TuyaOpen SDK is now ready.'
300296
Write-Host 'Exit environment: `deactivate`.'
301297

302298
# ---------------------------------------------------------------------------

export.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ if [ -n "$BASH_VERSION" ]; then
302302
fi
303303

304304
# ---------------------------------------------------------------------------
305-
# Greeting banner — rendered by `tos.py hello`.
305+
# Greeting banner — ASCII/version from `tos.py hello`; "ready" + exit hint
306+
# from this script so shells can show accurate wording (see export.ps1).
306307
# On re-source (and non-verbose) the tos.py "Running tos.py ..." INFO log on
307308
# stderr would be noise, so we drop stderr in that case.
308309
# ---------------------------------------------------------------------------
@@ -311,6 +312,8 @@ if [ "$__tuya_is_resource" = "1" ] && [ -z "$TUYAOPEN_EXPORT_VERBOSE" ]; then
311312
else
312313
tos.py hello --no-version
313314
fi
315+
echo 'tos.py Tool and TuyaOpen SDK is now ready.'
316+
echo 'Exit environment: `exit` or `deactivate`.'
314317
unset __tuya_is_resource
315318

316319
__tuya_export_cleanup

tools/cli_command/cli_hello.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python3
22
# coding=utf-8
33

4-
from typing import Optional
5-
64
import click
75

86
from tools.cli_command.cli_version import open_version
@@ -17,30 +15,18 @@
1715
"""
1816

1917

20-
DEFAULT_EXIT_HINT = "Exit environment: `exit` or `deactivate`."
21-
22-
23-
def print_hello(show_version: bool = True, exit_hint: Optional[str] = None) -> None:
18+
def print_hello(show_version: bool = True) -> None:
2419
"""Print the TuyaOpen greeting banner.
2520
2621
Args:
2722
show_version: include the TuyaOpen version line when True.
28-
exit_hint: trailing "how to exit" line.
29-
* None (default) -> use DEFAULT_EXIT_HINT
30-
* "" -> suppress the hint line entirely
31-
* anything else -> print that string verbatim
3223
"""
3324
separator = "*" * 40
3425
click.echo(separator)
3526
click.echo(HELLO_BANNER)
3627
if show_version:
3728
click.echo(f"TuyaOpen version: {open_version()}")
3829
click.echo(separator)
39-
click.echo("tos.py Tool and TuyaOpen SDK is now ready.")
40-
if exit_hint is None:
41-
click.echo(DEFAULT_EXIT_HINT)
42-
elif exit_hint != "":
43-
click.echo(exit_hint)
4430

4531

4632
##
@@ -51,11 +37,6 @@ def print_hello(show_version: bool = True, exit_hint: Optional[str] = None) -> N
5137
@click.option("--no-version",
5238
is_flag=True, default=False,
5339
help="Do not print the TuyaOpen version line.")
54-
@click.option("--exit-hint",
55-
type=str, default=None,
56-
help="Override the exit hint line. Pass an empty string to "
57-
"suppress the hint entirely. Useful for shell wrappers "
58-
"that want to print a shell-aware hint themselves.")
59-
def cli(no_version, exit_hint):
60-
print_hello(show_version=not no_version, exit_hint=exit_hint)
40+
def cli(no_version):
41+
print_hello(show_version=not no_version)
6142
pass

0 commit comments

Comments
 (0)