hainiubl-cloud-files 0.1.0 → 0.1.1
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.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/cli.js +24 -4
package/README.md
CHANGED
|
@@ -8,13 +8,13 @@ hainiubl 云端沙箱官方文件传输客户端。零第三方依赖,安装
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm i -g hainiubl-cloud-files
|
|
11
|
-
hainiubl-cloud-files --
|
|
11
|
+
hainiubl-cloud-files --version
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
也可以不安装直接运行:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npx -y hainiubl-cloud-files@0.1.
|
|
17
|
+
npx -y hainiubl-cloud-files@0.1.1 --version
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## 完整模式(人类用户)
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { constants } from 'node:fs';
|
|
2
|
+
import { constants, realpathSync } from 'node:fs';
|
|
3
3
|
import { lstat, open } from 'node:fs/promises';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { FileClient, hashFile, validateTicketDescriptor } from './client.js';
|
|
7
|
-
import { loadFileClientConfig } from './config.js';
|
|
7
|
+
import { loadFileClientConfig, PACKAGE_VERSION } from './config.js';
|
|
8
8
|
import { exitCodeFor, fail, FileTransferError } from './errors.js';
|
|
9
9
|
|
|
10
10
|
const MAX_TICKET_BYTES = 1024 * 1024;
|
|
@@ -21,6 +21,7 @@ const HELP = `用法:
|
|
|
21
21
|
--overwrite 完整模式允许覆盖目标;票据下载允许覆盖已存在目标
|
|
22
22
|
--transfer-id ID 完整模式显式续传,须使用相同文件及任务参数
|
|
23
23
|
--ticket <文件|-> 票据模式;使用 MCP prepare 返回的 JSON,- 表示从 stdin 读取
|
|
24
|
+
--version 显示版本
|
|
24
25
|
--help 显示帮助
|
|
25
26
|
|
|
26
27
|
认证:完整模式读取 HAINIUBL_API_KEY,未设置时读取 ~/.hainiubl-cloud-mcp/api-key;
|
|
@@ -42,6 +43,9 @@ export function parseArguments(argv) {
|
|
|
42
43
|
if (argv.includes('--help') || argv.includes('-h')) {
|
|
43
44
|
return { help: true };
|
|
44
45
|
}
|
|
46
|
+
if (argv.includes('--version') || argv.includes('-v')) {
|
|
47
|
+
return { version: true };
|
|
48
|
+
}
|
|
45
49
|
const [command, ...rest] = argv;
|
|
46
50
|
if (!['upload', 'download', 'hash'].includes(command)) {
|
|
47
51
|
fail('ARGUMENT', '请指定 upload、download 或 hash,使用 --help 查看用法');
|
|
@@ -211,6 +215,10 @@ export async function main(argv = process.argv.slice(2), {
|
|
|
211
215
|
stdout.write(HELP);
|
|
212
216
|
return;
|
|
213
217
|
}
|
|
218
|
+
if (args.version) {
|
|
219
|
+
stdout.write(`${PACKAGE_VERSION}\n`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
214
222
|
if (args.command === 'hash') {
|
|
215
223
|
const result = await hashFile(args.source);
|
|
216
224
|
stdout.write(`${JSON.stringify(result)}\n`);
|
|
@@ -283,6 +291,18 @@ function runCli() {
|
|
|
283
291
|
main().catch(error => reportError(error));
|
|
284
292
|
}
|
|
285
293
|
|
|
286
|
-
|
|
294
|
+
// npm 安装后的 .bin 是符号链接;必须比较真实路径,否则 npx 调用会静默不执行 main。
|
|
295
|
+
function isEntryPoint() {
|
|
296
|
+
if (!process.argv[1]) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
301
|
+
} catch {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (isEntryPoint()) {
|
|
287
307
|
runCli();
|
|
288
308
|
}
|