@atomservice/cli 0.1.2 → 0.1.4
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/bin/atom.ts +10 -3
- package/package.json +8 -8
package/bin/atom.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { UserError } from "@atomservice/core"
|
|
3
3
|
import { type ArgsDef, type CommandDef, defineCommand, renderUsage, runCommand, runMain } from "citty"
|
|
4
4
|
import pc from "picocolors"
|
|
5
|
+
import pkg from "../package.json" with { type: "json" }
|
|
5
6
|
import { addCmd } from "../src/add/add.cmd.ts"
|
|
6
7
|
import { initCmd } from "../src/init/init.cmd.ts"
|
|
7
8
|
import { runCmd } from "../src/run/index.ts"
|
|
@@ -19,7 +20,7 @@ async function showUsage<T extends ArgsDef>(cmd: CommandDef<T>, parent?: Command
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const main = defineCommand({
|
|
22
|
-
meta: { name: "atom", version:
|
|
23
|
+
meta: { name: "atom", version: pkg.version, description: "原子化自托管服务编排工具" },
|
|
23
24
|
subCommands: async () => ({
|
|
24
25
|
init: initCmd,
|
|
25
26
|
add: addCmd,
|
|
@@ -37,9 +38,15 @@ const wantsHelpOrVersion =
|
|
|
37
38
|
argv.includes("--help") || argv.includes("-h") || (argv.length === 1 && argv[0] === "--version")
|
|
38
39
|
|
|
39
40
|
if (wantsHelpOrVersion) {
|
|
40
|
-
// help / version 由 citty 自带逻辑处理
|
|
41
41
|
await runMain(main, { showUsage })
|
|
42
42
|
} else {
|
|
43
|
+
const subCommands = await (main.subCommands as () => Promise<Record<string, unknown>>)()
|
|
44
|
+
const requested = argv.find((a) => !a.startsWith("-"))
|
|
45
|
+
if (requested && !(requested in subCommands)) {
|
|
46
|
+
console.error(`\n${pc.red("✗")} ${pc.yellow(requested)} 不是有效的命令\n`)
|
|
47
|
+
await showUsage(main)
|
|
48
|
+
process.exit(1)
|
|
49
|
+
}
|
|
43
50
|
try {
|
|
44
51
|
await runCommand(main, { rawArgs: argv })
|
|
45
52
|
} catch (err) {
|
|
@@ -48,7 +55,7 @@ if (wantsHelpOrVersion) {
|
|
|
48
55
|
if (err.hint) console.error(pc.dim(` ${err.hint}`))
|
|
49
56
|
} else {
|
|
50
57
|
console.error(`\n${pc.red("✗")} ${err instanceof Error ? err.message : String(err)}`)
|
|
51
|
-
console.error(pc.dim("
|
|
58
|
+
console.error(pc.dim(" 遇到意外错误,使用 --verbose 查看错误详情"))
|
|
52
59
|
if (process.env.ATOMSERVICE_VERBOSE && err instanceof Error && err.stack) {
|
|
53
60
|
console.error(pc.dim(err.stack))
|
|
54
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomservice/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "atomservice 命令行工具(atom):init / run / add / service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "openorson",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"atom": "./bin/atom.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@clack/prompts": "
|
|
33
|
-
"@atomservice/core": "0.1.
|
|
34
|
-
"citty": "
|
|
35
|
-
"cli-table3": "
|
|
36
|
-
"log-update": "
|
|
37
|
-
"ora": "
|
|
38
|
-
"picocolors": "
|
|
32
|
+
"@clack/prompts": "1.5.0",
|
|
33
|
+
"@atomservice/core": "0.1.4",
|
|
34
|
+
"citty": "0.2.2",
|
|
35
|
+
"cli-table3": "0.6.5",
|
|
36
|
+
"log-update": "8.0.0",
|
|
37
|
+
"ora": "9.4.0",
|
|
38
|
+
"picocolors": "1.1.1"
|
|
39
39
|
}
|
|
40
40
|
}
|