compshare-cli 0.2.1__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. compshare_cli-0.3.1/PKG-INFO +246 -0
  2. compshare_cli-0.3.1/README.md +221 -0
  3. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/pyproject.toml +3 -1
  4. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/__init__.py +1 -1
  5. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/actions.py +4 -0
  6. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/api.py +19 -13
  7. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/cli.py +87 -14
  8. compshare_cli-0.3.1/src/compshare_cli/commands/ask.py +31 -0
  9. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/common.py +8 -9
  10. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/doctor.py +15 -3
  11. compshare_cli-0.3.1/src/compshare_cli/commands/feedback.py +20 -0
  12. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/image.py +50 -37
  13. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/instance.py +269 -117
  14. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/storage.py +23 -18
  15. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/team.py +16 -16
  16. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/config.py +5 -5
  17. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/i18n.py +89 -12
  18. compshare_cli-0.3.1/src/compshare_cli/insights.py +146 -0
  19. compshare_cli-0.3.1/src/compshare_cli/location.py +85 -0
  20. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/output.py +57 -11
  21. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/parsing.py +13 -0
  22. compshare_cli-0.3.1/src/compshare_cli/qa.py +51 -0
  23. compshare_cli-0.3.1/src/compshare_cli/runtime.py +20 -0
  24. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/sdk.py +2 -2
  25. compshare_cli-0.3.1/src/compshare_cli/ssh.py +256 -0
  26. compshare_cli-0.3.1/src/compshare_cli.egg-info/PKG-INFO +246 -0
  27. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli.egg-info/SOURCES.txt +9 -1
  28. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli.egg-info/entry_points.txt +1 -0
  29. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli.egg-info/requires.txt +3 -0
  30. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/tests/test_actions.py +9 -2
  31. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/tests/test_api.py +19 -0
  32. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/tests/test_cli.py +649 -27
  33. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/tests/test_config.py +3 -14
  34. compshare_cli-0.3.1/tests/test_feedback.py +154 -0
  35. compshare_cli-0.3.1/tests/test_location.py +103 -0
  36. compshare_cli-0.3.1/tests/test_output.py +61 -0
  37. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/tests/test_parsing.py +4 -0
  38. compshare_cli-0.3.1/tests/test_qa.py +121 -0
  39. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/tests/test_sdk.py +6 -0
  40. compshare_cli-0.3.1/tests/test_ssh.py +242 -0
  41. compshare_cli-0.2.1/PKG-INFO +0 -180
  42. compshare_cli-0.2.1/README.md +0 -156
  43. compshare_cli-0.2.1/src/compshare_cli/location.py +0 -91
  44. compshare_cli-0.2.1/src/compshare_cli/runtime.py +0 -34
  45. compshare_cli-0.2.1/src/compshare_cli.egg-info/PKG-INFO +0 -180
  46. compshare_cli-0.2.1/tests/test_location.py +0 -39
  47. compshare_cli-0.2.1/tests/test_output.py +0 -28
  48. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/LICENSE +0 -0
  49. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/setup.cfg +0 -0
  50. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/__main__.py +0 -0
  51. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/commands/__init__.py +0 -0
  52. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli/errors.py +0 -0
  53. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli.egg-info/dependency_links.txt +0 -0
  54. {compshare_cli-0.2.1 → compshare_cli-0.3.1}/src/compshare_cli.egg-info/top_level.txt +0 -0
@@ -0,0 +1,246 @@
1
+ Metadata-Version: 2.4
2
+ Name: compshare-cli
3
+ Version: 0.3.1
4
+ Summary: Command-line client for CompShare GPU compute
5
+ Author: CompShare
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/BennielAllan/compshare-cli
8
+ Project-URL: Repository, https://github.com/BennielAllan/compshare-cli
9
+ Project-URL: Changelog, https://github.com/BennielAllan/compshare-cli/blob/master/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/BennielAllan/compshare-cli/issues
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: click<9,>=8.1
15
+ Requires-Dist: pexpect<5,>=4.9; platform_system != "Windows"
16
+ Requires-Dist: rich<15,>=13
17
+ Requires-Dist: typer<1,>=0.12
18
+ Requires-Dist: ucloud-sdk-python3<0.12,>=0.11.103
19
+ Requires-Dist: urllib3<2,>=1.26.18; python_version < "3.10" and platform_system == "Darwin"
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest<10,>=8; extra == "dev"
22
+ Requires-Dist: pytest-cov<8,>=5; extra == "dev"
23
+ Requires-Dist: ruff<1,>=0.6; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # CompShare CLI
27
+
28
+ 在终端管理优云智算 GPU 实例、镜像、云盘、US3 挂载和团队资源。
29
+
30
+ - 交互式创建实例,实时查询规格、库存和价格
31
+ - 支持批量生命周期操作、等待状态和跨地域查询
32
+ - 支持社区/自定义镜像、云盘、团队额度与账单
33
+ - 默认中文帮助,可切换英文;所有命令支持 JSON 输出
34
+ - 可通过 `compshare ask` 查询产品使用和计费知识
35
+ - 可通过 `compshare feedback` 反馈 CLI 问题和建议
36
+ - 基于官方 [`ucloud-sdk-python3`](https://github.com/ucloud/ucloud-sdk-python3)
37
+
38
+ 当前版本:`0.3.1`,要求 Python 3.9 或更高版本。
39
+
40
+ ## 安装
41
+
42
+ ```bash
43
+ pip install compshare-cli
44
+ compshare -h
45
+ ```
46
+
47
+ 本地开发:
48
+
49
+ ```bash
50
+ git clone https://github.com/BennielAllan/compshare-cli.git
51
+ cd compshare-cli
52
+ python -m venv .venv
53
+ source .venv/bin/activate
54
+ python -m pip install -e '.[dev]'
55
+ ```
56
+
57
+ Windows PowerShell 中可先激活虚拟环境,再直接调用 `compshare`:
58
+
59
+ ```powershell
60
+ .\.venv\Scripts\Activate.ps1
61
+ compshare -h
62
+ compshare config --name default
63
+ ```
64
+
65
+ 不激活虚拟环境时,使用 PowerShell 调用运算符 `&` 直接执行虚拟环境内的入口:
66
+
67
+ ```powershell
68
+ & '.\.venv\Scripts\compshare.exe' -h
69
+ & '.\.venv\Scripts\compshare.exe' config --name default
70
+ ```
71
+
72
+ PowerShell 会把单引号中的路径解析为字符串,所以带参数执行时不能省略 `&`。路径包含空格时必须保留引号;从当前目录运行可执行文件时要使用 `.\` 前缀。若 `Activate.ps1` 被本机执行策略拦截,可直接使用上述不激活的写法,无需修改系统策略。
73
+
74
+ ## 配置
75
+
76
+ ```bash
77
+ compshare config --name default
78
+ ```
79
+
80
+ 凭证保存在 `~/.config/compshare/config.json`,支持多个配置:
81
+
82
+ ```bash
83
+ compshare config list
84
+ compshare config use production
85
+ compshare --profile production instance list
86
+ ```
87
+
88
+ 也可以使用环境变量:
89
+
90
+ ```bash
91
+ export COMPSHARE_PUBLIC_KEY='...'
92
+ export COMPSHARE_PRIVATE_KEY='...'
93
+ ```
94
+
95
+ ## 快速开始
96
+
97
+ ```bash
98
+ # 查规格、库存和实例
99
+ compshare instance search --region cn-sh2 --zone cn-sh2-02
100
+ compshare instance search --region cn-sh2 --zone cn-sh2-02 \
101
+ --gpu 4090 --image IMAGE_ID --available
102
+ compshare instance list --all
103
+
104
+ # 交互式创建
105
+ compshare instance create
106
+
107
+ # 批量操作与等待
108
+ compshare instance stop INSTANCE_1 INSTANCE_2
109
+ compshare instance start INSTANCE_1 INSTANCE_2
110
+ compshare instance wait INSTANCE_1 INSTANCE_2 --state Running
111
+
112
+ # SSH
113
+ compshare instance ssh INSTANCE_ID
114
+ # 默认自动填写 API 返回的密码;需要手动输入时可关闭
115
+ compshare instance ssh INSTANCE_ID --no-auto-password
116
+ # 自动登录后执行远程命令;远程参数用 -- 与 CLI 选项分隔
117
+ compshare instance ssh INSTANCE_ID -- nvidia-smi --query-gpu=name
118
+ compshare instance ssh INSTANCE_ID -- 'cd /workspace && python train.py'
119
+ # 上传本地文件或目录,目录会自动递归复制
120
+ compshare instance scp INSTANCE_ID ./model.bin /workspace/model.bin
121
+ compshare instance scp INSTANCE_ID ./dataset /workspace/dataset
122
+
123
+ # 产品问答
124
+ compshare ask "按量实例关机以后,云硬盘还收费吗?"
125
+ ```
126
+
127
+ 自动化创建示例:
128
+
129
+ ```bash
130
+ compshare instance create \
131
+ --region cn-sh2 \
132
+ --zone cn-sh2-02 \
133
+ --gpu 4090 \
134
+ --count 1 \
135
+ --cpu 16 \
136
+ --memory 64GiB \
137
+ --image IMAGE_ID \
138
+ --disk 100GiB \
139
+ --charge Postpay \
140
+ --max-price 20 \
141
+ --yes
142
+ ```
143
+
144
+ 使用 `--dry-run` 只检查库存、价格和请求,不创建资源。
145
+
146
+ ## 功能入口
147
+
148
+ ```text
149
+ compshare instance GPU 实例、规格、库存、价格和生命周期
150
+ compshare image 平台、自定义、社区及共享镜像
151
+ compshare storage 云盘和 US3 挂载
152
+ compshare team 团队、邀请、成员额度、账单和审计
153
+ compshare doctor 配置、鉴权、网络与 SSH 环境诊断
154
+ compshare ask 产品使用和计费问答
155
+ compshare feedback 反馈 CLI 问题或建议
156
+ ```
157
+
158
+ ## 产品问答
159
+
160
+ ```bash
161
+ compshare ask "按量实例关机以后,云硬盘还收费吗?"
162
+ compshare --json ask "如何创建自定义镜像?"
163
+ ```
164
+
165
+ 普通输出显示答案和引用资料标题;`--json` 返回完整的答案、引用、请求 ID 和检索元数据。
166
+ 命令只向内置问答服务发送 `question` 字段,不会附带 API 凭证、配置文件或其他命令上下文。
167
+
168
+ ## 反馈
169
+
170
+ ```bash
171
+ compshare feedback bug "创建实例时发生错误"
172
+ compshare feedback suggest "希望支持保存默认创建规格"
173
+ ```
174
+
175
+ 反馈会直接发送到内置的 CompShare Insights 服务地址。开发环境可使用
176
+ `COMPSHARE_INSIGHTS_URL=http://127.0.0.1:18080` 覆盖服务地址。
177
+
178
+ CLI 会异步统计指令使用情况,且仅发送指令名称、CLI 版本、操作系统和发生时间;不会发送
179
+ 命令参数、凭证、资源 ID 或命令输出。
180
+
181
+ 查看完整命令和参数:
182
+
183
+ ```bash
184
+ compshare -h
185
+ compshare instance -h
186
+ compshare instance create -h
187
+ ```
188
+
189
+ ## 脚本调用
190
+
191
+ `--json`、`--profile` 和 `--show-sensitive` 是全局选项,必须放在子命令前:
192
+
193
+ ```bash
194
+ compshare --json instance list --status Running --all
195
+ compshare --profile production image list --source community --region cn-sh2 --zone cn-sh2-02
196
+ compshare --json --show-sensitive instance show uhost-xxxxxxxx
197
+ ```
198
+
199
+ JSON 模式不会启动交互向导。生命周期操作可使用 `--wait`、`--no-wait` 和
200
+ `--timeout` 控制等待行为;部分批量操作失败时,CLI 返回非零退出码。默认输出会递归隐藏
201
+ 密码、IP、访问 URL 和登录命令;只有显式指定 `--show-sensitive` 才会输出原值。
202
+
203
+ Region 和 Zone 是资源参数,放在对应子命令后:
204
+
205
+ ```bash
206
+ compshare instance list --region cn-sh2
207
+ compshare instance create --region cn-sh2 --zone cn-sh2-02
208
+ compshare image list --source custom --region cn-sh2 --zone cn-sh2-02
209
+ ```
210
+
211
+ CLI 不保存或自动注入默认 Region/Zone。非交互式地域资源操作需要显式传入;按实例 ID
212
+ 执行的生命周期操作使用 `DescribeCompShareInstance` 响应中的 Region 和 Zone;响应缺少任一
213
+ 字段时会停止操作,不会从 Zone 推导或用请求 Region 补齐。
214
+
215
+ ## 语言
216
+
217
+ ```bash
218
+ compshare lang en
219
+ compshare lang zh
220
+ compshare lang # 查看当前语言
221
+ ```
222
+
223
+ 也可以通过 `COMPSHARE_LANG=en` 临时覆盖。
224
+
225
+ ## 安全说明
226
+
227
+ - 配置目录和文件分别使用 `0700`、`0600` 权限。
228
+ - API 私钥不会出现在命令输出中。
229
+ - 默认使用 `***` 隐藏密码、私钥、IP、访问 URL、令牌和登录命令,包括嵌套 JSON 字段。
230
+ - `instance ssh` 在支持的交互式终端中通过伪终端自动填写登录密码,不会打印密码或将其放入进程参数。
231
+ - 自动登录会接受首次出现的 SSH 主机密钥;已记录主机的密钥发生变化时仍会拒绝连接。
232
+ - `instance ssh INSTANCE_ID -- COMMAND` 可非交互执行远程命令,透传命令输出和退出码。
233
+ - `instance scp INSTANCE_ID LOCAL_PATH REMOTE_PATH` 可自动认证并上传本地文件或目录。
234
+ - `--show-sensitive` 会恢复这些字段的原始值;请勿在共享终端、CI 日志或 Agent 会话中使用。
235
+ - 删除、关机、重启、重装和改配等操作默认要求确认。
236
+
237
+ ## 开发校验
238
+
239
+ ```bash
240
+ ruff check .
241
+ ruff format --check .
242
+ pytest
243
+ ```
244
+
245
+ 公开 API 覆盖范围和版本变化见 [CHANGELOG.md](CHANGELOG.md),维护者发布流程见
246
+ [RELEASING.md](RELEASING.md)。
@@ -0,0 +1,221 @@
1
+ # CompShare CLI
2
+
3
+ 在终端管理优云智算 GPU 实例、镜像、云盘、US3 挂载和团队资源。
4
+
5
+ - 交互式创建实例,实时查询规格、库存和价格
6
+ - 支持批量生命周期操作、等待状态和跨地域查询
7
+ - 支持社区/自定义镜像、云盘、团队额度与账单
8
+ - 默认中文帮助,可切换英文;所有命令支持 JSON 输出
9
+ - 可通过 `compshare ask` 查询产品使用和计费知识
10
+ - 可通过 `compshare feedback` 反馈 CLI 问题和建议
11
+ - 基于官方 [`ucloud-sdk-python3`](https://github.com/ucloud/ucloud-sdk-python3)
12
+
13
+ 当前版本:`0.3.1`,要求 Python 3.9 或更高版本。
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ pip install compshare-cli
19
+ compshare -h
20
+ ```
21
+
22
+ 本地开发:
23
+
24
+ ```bash
25
+ git clone https://github.com/BennielAllan/compshare-cli.git
26
+ cd compshare-cli
27
+ python -m venv .venv
28
+ source .venv/bin/activate
29
+ python -m pip install -e '.[dev]'
30
+ ```
31
+
32
+ Windows PowerShell 中可先激活虚拟环境,再直接调用 `compshare`:
33
+
34
+ ```powershell
35
+ .\.venv\Scripts\Activate.ps1
36
+ compshare -h
37
+ compshare config --name default
38
+ ```
39
+
40
+ 不激活虚拟环境时,使用 PowerShell 调用运算符 `&` 直接执行虚拟环境内的入口:
41
+
42
+ ```powershell
43
+ & '.\.venv\Scripts\compshare.exe' -h
44
+ & '.\.venv\Scripts\compshare.exe' config --name default
45
+ ```
46
+
47
+ PowerShell 会把单引号中的路径解析为字符串,所以带参数执行时不能省略 `&`。路径包含空格时必须保留引号;从当前目录运行可执行文件时要使用 `.\` 前缀。若 `Activate.ps1` 被本机执行策略拦截,可直接使用上述不激活的写法,无需修改系统策略。
48
+
49
+ ## 配置
50
+
51
+ ```bash
52
+ compshare config --name default
53
+ ```
54
+
55
+ 凭证保存在 `~/.config/compshare/config.json`,支持多个配置:
56
+
57
+ ```bash
58
+ compshare config list
59
+ compshare config use production
60
+ compshare --profile production instance list
61
+ ```
62
+
63
+ 也可以使用环境变量:
64
+
65
+ ```bash
66
+ export COMPSHARE_PUBLIC_KEY='...'
67
+ export COMPSHARE_PRIVATE_KEY='...'
68
+ ```
69
+
70
+ ## 快速开始
71
+
72
+ ```bash
73
+ # 查规格、库存和实例
74
+ compshare instance search --region cn-sh2 --zone cn-sh2-02
75
+ compshare instance search --region cn-sh2 --zone cn-sh2-02 \
76
+ --gpu 4090 --image IMAGE_ID --available
77
+ compshare instance list --all
78
+
79
+ # 交互式创建
80
+ compshare instance create
81
+
82
+ # 批量操作与等待
83
+ compshare instance stop INSTANCE_1 INSTANCE_2
84
+ compshare instance start INSTANCE_1 INSTANCE_2
85
+ compshare instance wait INSTANCE_1 INSTANCE_2 --state Running
86
+
87
+ # SSH
88
+ compshare instance ssh INSTANCE_ID
89
+ # 默认自动填写 API 返回的密码;需要手动输入时可关闭
90
+ compshare instance ssh INSTANCE_ID --no-auto-password
91
+ # 自动登录后执行远程命令;远程参数用 -- 与 CLI 选项分隔
92
+ compshare instance ssh INSTANCE_ID -- nvidia-smi --query-gpu=name
93
+ compshare instance ssh INSTANCE_ID -- 'cd /workspace && python train.py'
94
+ # 上传本地文件或目录,目录会自动递归复制
95
+ compshare instance scp INSTANCE_ID ./model.bin /workspace/model.bin
96
+ compshare instance scp INSTANCE_ID ./dataset /workspace/dataset
97
+
98
+ # 产品问答
99
+ compshare ask "按量实例关机以后,云硬盘还收费吗?"
100
+ ```
101
+
102
+ 自动化创建示例:
103
+
104
+ ```bash
105
+ compshare instance create \
106
+ --region cn-sh2 \
107
+ --zone cn-sh2-02 \
108
+ --gpu 4090 \
109
+ --count 1 \
110
+ --cpu 16 \
111
+ --memory 64GiB \
112
+ --image IMAGE_ID \
113
+ --disk 100GiB \
114
+ --charge Postpay \
115
+ --max-price 20 \
116
+ --yes
117
+ ```
118
+
119
+ 使用 `--dry-run` 只检查库存、价格和请求,不创建资源。
120
+
121
+ ## 功能入口
122
+
123
+ ```text
124
+ compshare instance GPU 实例、规格、库存、价格和生命周期
125
+ compshare image 平台、自定义、社区及共享镜像
126
+ compshare storage 云盘和 US3 挂载
127
+ compshare team 团队、邀请、成员额度、账单和审计
128
+ compshare doctor 配置、鉴权、网络与 SSH 环境诊断
129
+ compshare ask 产品使用和计费问答
130
+ compshare feedback 反馈 CLI 问题或建议
131
+ ```
132
+
133
+ ## 产品问答
134
+
135
+ ```bash
136
+ compshare ask "按量实例关机以后,云硬盘还收费吗?"
137
+ compshare --json ask "如何创建自定义镜像?"
138
+ ```
139
+
140
+ 普通输出显示答案和引用资料标题;`--json` 返回完整的答案、引用、请求 ID 和检索元数据。
141
+ 命令只向内置问答服务发送 `question` 字段,不会附带 API 凭证、配置文件或其他命令上下文。
142
+
143
+ ## 反馈
144
+
145
+ ```bash
146
+ compshare feedback bug "创建实例时发生错误"
147
+ compshare feedback suggest "希望支持保存默认创建规格"
148
+ ```
149
+
150
+ 反馈会直接发送到内置的 CompShare Insights 服务地址。开发环境可使用
151
+ `COMPSHARE_INSIGHTS_URL=http://127.0.0.1:18080` 覆盖服务地址。
152
+
153
+ CLI 会异步统计指令使用情况,且仅发送指令名称、CLI 版本、操作系统和发生时间;不会发送
154
+ 命令参数、凭证、资源 ID 或命令输出。
155
+
156
+ 查看完整命令和参数:
157
+
158
+ ```bash
159
+ compshare -h
160
+ compshare instance -h
161
+ compshare instance create -h
162
+ ```
163
+
164
+ ## 脚本调用
165
+
166
+ `--json`、`--profile` 和 `--show-sensitive` 是全局选项,必须放在子命令前:
167
+
168
+ ```bash
169
+ compshare --json instance list --status Running --all
170
+ compshare --profile production image list --source community --region cn-sh2 --zone cn-sh2-02
171
+ compshare --json --show-sensitive instance show uhost-xxxxxxxx
172
+ ```
173
+
174
+ JSON 模式不会启动交互向导。生命周期操作可使用 `--wait`、`--no-wait` 和
175
+ `--timeout` 控制等待行为;部分批量操作失败时,CLI 返回非零退出码。默认输出会递归隐藏
176
+ 密码、IP、访问 URL 和登录命令;只有显式指定 `--show-sensitive` 才会输出原值。
177
+
178
+ Region 和 Zone 是资源参数,放在对应子命令后:
179
+
180
+ ```bash
181
+ compshare instance list --region cn-sh2
182
+ compshare instance create --region cn-sh2 --zone cn-sh2-02
183
+ compshare image list --source custom --region cn-sh2 --zone cn-sh2-02
184
+ ```
185
+
186
+ CLI 不保存或自动注入默认 Region/Zone。非交互式地域资源操作需要显式传入;按实例 ID
187
+ 执行的生命周期操作使用 `DescribeCompShareInstance` 响应中的 Region 和 Zone;响应缺少任一
188
+ 字段时会停止操作,不会从 Zone 推导或用请求 Region 补齐。
189
+
190
+ ## 语言
191
+
192
+ ```bash
193
+ compshare lang en
194
+ compshare lang zh
195
+ compshare lang # 查看当前语言
196
+ ```
197
+
198
+ 也可以通过 `COMPSHARE_LANG=en` 临时覆盖。
199
+
200
+ ## 安全说明
201
+
202
+ - 配置目录和文件分别使用 `0700`、`0600` 权限。
203
+ - API 私钥不会出现在命令输出中。
204
+ - 默认使用 `***` 隐藏密码、私钥、IP、访问 URL、令牌和登录命令,包括嵌套 JSON 字段。
205
+ - `instance ssh` 在支持的交互式终端中通过伪终端自动填写登录密码,不会打印密码或将其放入进程参数。
206
+ - 自动登录会接受首次出现的 SSH 主机密钥;已记录主机的密钥发生变化时仍会拒绝连接。
207
+ - `instance ssh INSTANCE_ID -- COMMAND` 可非交互执行远程命令,透传命令输出和退出码。
208
+ - `instance scp INSTANCE_ID LOCAL_PATH REMOTE_PATH` 可自动认证并上传本地文件或目录。
209
+ - `--show-sensitive` 会恢复这些字段的原始值;请勿在共享终端、CI 日志或 Agent 会话中使用。
210
+ - 删除、关机、重启、重装和改配等操作默认要求确认。
211
+
212
+ ## 开发校验
213
+
214
+ ```bash
215
+ ruff check .
216
+ ruff format --check .
217
+ pytest
218
+ ```
219
+
220
+ 公开 API 覆盖范围和版本变化见 [CHANGELOG.md](CHANGELOG.md),维护者发布流程见
221
+ [RELEASING.md](RELEASING.md)。
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "compshare-cli"
7
- version = "0.2.1"
7
+ version = "0.3.1"
8
8
  description = "Command-line client for CompShare GPU compute"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -15,6 +15,7 @@ authors = [
15
15
  ]
16
16
  dependencies = [
17
17
  "click>=8.1,<9",
18
+ "pexpect>=4.9,<5; platform_system != 'Windows'",
18
19
  "rich>=13,<15",
19
20
  "typer>=0.12,<1",
20
21
  "ucloud-sdk-python3>=0.11.103,<0.12",
@@ -36,6 +37,7 @@ dev = [
36
37
 
37
38
  [project.scripts]
38
39
  compshare = "compshare_cli.cli:main"
40
+ compshare-ssh-askpass = "compshare_cli.ssh:askpass"
39
41
 
40
42
  [tool.setuptools.packages.find]
41
43
  where = ["src"]
@@ -1,3 +1,3 @@
1
1
  """CompShare command-line client."""
2
2
 
3
- __version__ = "0.2.1"
3
+ __version__ = "0.3.1"
@@ -89,5 +89,9 @@ TEAM_ACTIONS = frozenset(
89
89
 
90
90
  PUBLIC_ACTIONS = INSTANCE_ACTIONS | IMAGE_ACTIONS | STORAGE_ACTIONS | TEAM_ACTIONS
91
91
 
92
+ # Public API actions intentionally exposed as CLI placeholders until their
93
+ # production request contract is ready.
94
+ COMING_SOON_ACTIONS = frozenset({"GetCompShareInstanceMonitor"})
95
+
92
96
  # Documented publicly but unavailable in the production API (RetCode 161).
93
97
  UNAVAILABLE_ACTIONS = frozenset({"DescribeFavoriteImages"})
@@ -13,6 +13,12 @@ from compshare_cli.runtime import Runtime
13
13
  from compshare_cli.sdk import CompShareSDK
14
14
 
15
15
 
16
+ def _sdk(runtime: Runtime, params: Dict[str, Any]) -> CompShareSDK:
17
+ raw_region = params.get("Region")
18
+ region = str(raw_region) if raw_region is not None else None
19
+ return CompShareSDK(runtime.profile, region)
20
+
21
+
16
22
  def invoke(
17
23
  runtime: Runtime,
18
24
  action: str,
@@ -23,13 +29,13 @@ def invoke(
23
29
  columns: Optional[Sequence[Tuple[str, str]]] = None,
24
30
  success: Optional[str] = None,
25
31
  ) -> Dict[str, Any]:
26
- renderer = Renderer(runtime.json_output)
32
+ renderer = Renderer(runtime.json_output, runtime.show_sensitive)
27
33
  retries = 3 if action == "DeleteCompshareDisk" else 0
28
34
  attempt = 0
29
35
  try:
30
36
  while True:
31
37
  try:
32
- response = CompShareSDK(runtime.profile, runtime.region).invoke(action, params)
38
+ response = _sdk(runtime, params).invoke(action, params)
33
39
  break
34
40
  except ucloud_exc.RetCodeException as error:
35
41
  if error.code == 8434 and attempt < retries:
@@ -80,13 +86,13 @@ def invoke(
80
86
  def call(runtime: Runtime, action: str, params: Dict[str, Any]) -> Dict[str, Any]:
81
87
  """Invoke without rendering, for commands that combine multiple API calls."""
82
88
  try:
83
- return CompShareSDK(runtime.profile, runtime.region).invoke(action, params)
89
+ return _sdk(runtime, params).invoke(action, params)
84
90
  except CLIError as error:
85
- Renderer(runtime.json_output).error(str(error))
91
+ Renderer(runtime.json_output, runtime.show_sensitive).error(str(error))
86
92
  raise typer.Exit(1) from error
87
93
  except ucloud_exc.RetCodeException as error:
88
94
  hint = error_hint(error.action or action, error.code)
89
- Renderer(runtime.json_output).error(
95
+ Renderer(runtime.json_output, runtime.show_sensitive).error(
90
96
  _with_hint(error.message or str(error), hint),
91
97
  details={
92
98
  "action": error.action,
@@ -97,10 +103,10 @@ def call(runtime: Runtime, action: str, params: Dict[str, Any]) -> Dict[str, Any
97
103
  )
98
104
  raise typer.Exit(1) from error
99
105
  except ucloud_exc.UCloudException as error:
100
- Renderer(runtime.json_output).error(str(error))
106
+ Renderer(runtime.json_output, runtime.show_sensitive).error(str(error))
101
107
  raise typer.Exit(1) from error
102
108
  except Exception as error:
103
- Renderer(runtime.json_output).error(str(error))
109
+ Renderer(runtime.json_output, runtime.show_sensitive).error(str(error))
104
110
  raise typer.Exit(1) from error
105
111
 
106
112
 
@@ -111,7 +117,7 @@ def call_captured(
111
117
  ) -> Tuple[Optional[Dict[str, Any]], Optional[Dict[str, Any]]]:
112
118
  """Invoke without rendering and return a structured error for batch operations."""
113
119
  try:
114
- return CompShareSDK(runtime.profile, runtime.region).invoke(action, params), None
120
+ return _sdk(runtime, params).invoke(action, params), None
115
121
  except CLIError as error:
116
122
  return None, {"message": str(error), "action": action}
117
123
  except ucloud_exc.RetCodeException as error:
@@ -187,13 +193,13 @@ def download_file(
187
193
  ) -> Tuple[bytes, Dict[str, str]]:
188
194
  """Download a non-JSON API response while preserving normal CLI error handling."""
189
195
  try:
190
- return CompShareSDK(runtime.profile, runtime.region).download(action, params)
196
+ return _sdk(runtime, params).download(action, params)
191
197
  except CLIError as error:
192
- Renderer(runtime.json_output).error(str(error))
198
+ Renderer(runtime.json_output, runtime.show_sensitive).error(str(error))
193
199
  raise typer.Exit(1) from error
194
200
  except ucloud_exc.RetCodeException as error:
195
201
  hint = error_hint(error.action or action, error.code)
196
- Renderer(runtime.json_output).error(
202
+ Renderer(runtime.json_output, runtime.show_sensitive).error(
197
203
  _with_hint(error.message or str(error), hint),
198
204
  details={
199
205
  "action": error.action or action,
@@ -204,10 +210,10 @@ def download_file(
204
210
  )
205
211
  raise typer.Exit(1) from error
206
212
  except ucloud_exc.UCloudException as error:
207
- Renderer(runtime.json_output).error(str(error))
213
+ Renderer(runtime.json_output, runtime.show_sensitive).error(str(error))
208
214
  raise typer.Exit(1) from error
209
215
  except Exception as error:
210
- Renderer(runtime.json_output).error(str(error))
216
+ Renderer(runtime.json_output, runtime.show_sensitive).error(str(error))
211
217
  raise typer.Exit(1) from error
212
218
 
213
219