8000 Fix build path and add shell completion by TNTinMinecraft · Pull Request #148 · tuya/TuyaOpen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix build path and add shell completion #148

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

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ Or add the TuyaOpen path to your system environment variables.

TuyaOpen can be compiled and debugged using the tos command, which will search for the TuyaOpen repository based on the path set in the environment variables and execute the corresponding operations.

For detailed usage of the tos command, please refer to [tos command](./docs/en/tos_guide.rst).
To enable auto-completion, add source `tools/completion/tos.sh` to your terminal environment configuration files such as `.bashrc` or `.zshrc`.

For detailed usage of the tos command, please refer to [tos command](docs/en/tos_guide.rst).

### Step2. Select the project to be compiled

Expand Down
14 changes: 8 additions & 6 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ $ export PATH=$PATH:$PWD

TuyaOpen 通过 tos 命令进行编译、调试等操作,tos 命令会根据环境变量中设置的路径查找 TuyaOpen 仓库,并执行对应操作。

tos 命令的详细使用方法,请参考 [tos 命令](./docs/zh/tos_guide.rst)。
如果希望使用自动补全,请将`tools/completion/tos.sh`使用`source`放入终端环境中,如`.bashrc`或`.zshrc`中。

tos 命令的详细使用方法,请参考 [tos 命令](docs/zh/tos_guide/index.rst)。

### step2. 选择待编译项目
- 方式1:编译 example
Expand Down Expand Up @@ -186,7 +188,7 @@ $ tos flash upgrade

## 示例工程 <span id="example"></span>

不同的芯片都会对应的示例,需在 TuyaOpen 根目录下通过 `tos set_example` 命令设置示例工程,可点击 [tos set_example](https://github.com/tuya/TuyaOpen/blob/master/docs/zh/tos_guide.md#%E8%AE%BE%E7%BD%AE%E7%A4%BA%E4%BE%8B) 了解详情。
不同的芯片都会对应的示例,需在 TuyaOpen 根目录下通过 `tos set_example` 命令设置示例工程,可点击 [tos set_example](docs/zh/tos_guide/index.rst#%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86) 了解详情。

```sh
$ tos set_example
Expand Down Expand Up @@ -255,19 +257,19 @@ tuya.ai 是一个综合性的 AI 服务平台,提供以下核心能力:
- 视频处理服务
- 多模态 AI 服务

详细使用说明请参考 [tuya.ai 文档](apps/tuya.ai/README.md)
详细使用说明请参考 [tuya.ai 文档](apps/tuya.ai/README_zh.md)

## 云连接应用

TuyaOpen 提供了丰富的云连接应用示例,相关应用位于 apps 目录下,可点击 [云连接应用](apps/tuya_cloud/README_zh.md)。

## platform 新增与适配

TuyaOpen 支持新增与适配新的 platform,具体操作请参考 [platform 新增与适配](./docs/zh/new_platform.rst)。
TuyaOpen 支持新增与适配新的 platform,具体操作请参考 [platform 新增与适配](./docs/zh/new_platform/index.rst)。

## board 新增与适配

TuyaOpen 支持新增与适配新的 board,具体操作请参考 [board 新增与适配](./docs/zh/new_board.rst)。
TuyaOpen 支持新增与适配新的 board,具体操作请参考 [board 新增与适配](./docs/zh/new_board/index.rst)。

## FAQ
1. TuyaOpen 支持的 platform 通过子仓库动态下载,更新 TuyaOpen 仓库不会主动更新子仓库,如遇到问题无法正常编译,请至 platform 文件夹下对应的目录下使用 `git pull` 命令更新,或删除 platform 文件夹下对应目录后再次下载。
Expand All @@ -278,7 +280,7 @@ TuyaOpen 支持新增与适配新的 board,具体操作请参考 [board 新增
本项目的分发遵循 Apache License 版本 2.0。有关更多信息,请参见 LICENSE 文件。

## 贡献代码
如果您对 TuyaOpen 感兴趣,并希望参与 TuyaOpen 的开发并成为代码贡献者,请先参阅 [贡献指南](./docs/zh/contribute_guide.rst)。
如果您对 TuyaOpen 感兴趣,并希望参与 TuyaOpen 的开发并成为代码贡献者,请先参阅 [贡献指南](./docs/zh/contribute_guide/index.rst)。

## 免责与责任条款

Expand Down
109 changes: 109 additions & 0 deletions tools/completion/tos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash

_tos_get_commands() {
echo "version check new build flash monitor clean fullclean menuconfig savedef config_choice set_example new_platform update help dev"
}

_tos_get_templates() {
echo "base auduino"
}

_tos_find_config_files() {
local config_dir="${1:-./config}"
[ -d "$config_dir" ] && find "$config_dir" -maxdepth 1 -name "*.config" -exec basename {} \; 2>/dev/null
}

_tos_get_dev_commands() {
echo "spc ceb bac"
}

_tos_get_flash_monitor_options() {
echo "-d -b"
}

if [ -n "$BASH_VERSION" ] && [ -z "$POSIXLY_CORRECT" ]; then
# Bash completion
if type complete >/dev/null 2>&1; then
_tos_completions() {
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=()

case ${prev} in
version|check|build|clean|fullclean|menuconfig|savedef|update|set_example|help)
return 0
;;
new)
COMPREPLY=( $(compgen -W "$(_tos_get_templates)" -- ${cur}) )
return 0
;;
config_choice)
local configs=$(_tos_find_config_files)
[ -n "$configs" ] && COMPREPLY=( $(compgen -W "${configs}" -- ${cur}) )
return 0
;;
flash|monitor)
[ "${COMP_WORDS[COMP_CWORD-2]}" = "-d" ] && return 0
COMPREPLY=( $(compgen -W "$(_tos_get_flash_monitor_options)" -- ${cur}) )
return 0
;;
dev)
COMPREPLY=( $(compgen -W "$(_tos_get_dev_commands)" -- ${cur}) )
return 0
;;
esac

[[ ${cur} == * ]] && COMPREPLY=( $(compgen -W "$(_tos_get_commands)" -- ${cur}) )
return 0
}

complete -F _tos_completions tos
fi

elif [ -n "$ZSH_VERSION" ]; then
# Zsh completion
{ autoload -U compinit && compinit -u; } &>/dev/null

if typeset -f compdef >/dev/null 2>&1; then
_tos() {
local state line
typeset -A opt_args

_arguments -C \
'1: :->command' \
'*: :->args'

case $state in
command)
local cmds=($(_tos_get_commands))
_describe -t commands 'command' cmds
;;
args)
case ${line[1]} in
new)
local templates=($(_tos_get_templates))
_describe -t templates 'templates' templates
;;
config_choice)
local configs=($(_tos_find_config_files))
_describe -t configs 'config files' configs
;;
flash|monitor)
if [[ ${line[-2]} != "-d" ]]; then
local options=($(_tos_get_flash_monitor_options))
_describe -t options 'options' options
fi
;;
dev)
local dev_cmds=($(_tos_get_dev_commands))
_describe -t dev_commands 'dev commands' dev_cmds
;;
esac
;;
esac
return 0
}

compdef _tos tos 2>/dev/null
fi
fi
2 changes: 1 addition & 1 deletion tos
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

OPEN_SDK_ROOT=$(cd "$(dirname "$0")" && pwd)
PROJECT_ROOT=$(pwd)
PROJECT_ROOT=$(pwd -P)
. $OPEN_SDK_ROOT/tools/util_tools.sh
LISTMENU=$OPEN_SDK_ROOT/tools/listmenu.sh

Expand Down
0