@yizhuan-cli/cli 0.1.5-beta.0 → 0.1.6-beta.0
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/package.json +9 -9
- package/src/index.js +3 -3
- package/src/params.test.js +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yizhuan-cli/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-beta.0",
|
|
4
4
|
"description": "易撰命令行工具,用于通过 API Key 查询易撰真实数据。",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -11,13 +11,6 @@
|
|
|
11
11
|
"src",
|
|
12
12
|
"README.md"
|
|
13
13
|
],
|
|
14
|
-
"scripts": {
|
|
15
|
-
"start": "node src/index.js",
|
|
16
|
-
"pack:dry-run": "npm pack --dry-run",
|
|
17
|
-
"smoke": "node src/index.js --help && node --test src/version.test.js",
|
|
18
|
-
"test:params": "node --test src/params.test.js",
|
|
19
|
-
"test:version": "node --test src/version.test.js"
|
|
20
|
-
},
|
|
21
14
|
"engines": {
|
|
22
15
|
"node": ">=22"
|
|
23
16
|
},
|
|
@@ -29,5 +22,12 @@
|
|
|
29
22
|
"license": "UNLICENSED",
|
|
30
23
|
"publishConfig": {
|
|
31
24
|
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "node src/index.js",
|
|
28
|
+
"pack:dry-run": "npm pack --dry-run",
|
|
29
|
+
"smoke": "node src/index.js --help && node --test src/version.test.js",
|
|
30
|
+
"test:params": "node --test src/params.test.js",
|
|
31
|
+
"test:version": "node --test src/version.test.js"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
package/src/index.js
CHANGED
|
@@ -131,7 +131,7 @@ function readFlagValue(argv, startIndex, key) {
|
|
|
131
131
|
let raw = argv[index]
|
|
132
132
|
if (raw == null) return { value: true, nextIndex: startIndex - 1 }
|
|
133
133
|
|
|
134
|
-
if (key === 'params' && /[{\[]/.test(raw)) {
|
|
134
|
+
if ((key === 'params' || key === 'json') && /[{\[]/.test(raw)) {
|
|
135
135
|
let joined = raw
|
|
136
136
|
while (!isBalancedJsonLike(joined) && index + 1 < argv.length && !String(argv[index + 1]).startsWith('--')) {
|
|
137
137
|
index += 1
|
|
@@ -155,13 +155,13 @@ export function parseArgs(argv) {
|
|
|
155
155
|
const body = value.slice(2)
|
|
156
156
|
const eqIndex = body.indexOf('=')
|
|
157
157
|
if (eqIndex > 0) {
|
|
158
|
-
const key = body.slice(0, eqIndex)
|
|
158
|
+
const key = body.slice(0, eqIndex).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
159
159
|
const raw = body.slice(eqIndex + 1)
|
|
160
160
|
args[key] = raw
|
|
161
161
|
continue
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
const key = body
|
|
164
|
+
const key = body.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
165
165
|
const next = argv[index + 1]
|
|
166
166
|
if (!next || next.startsWith('--')) {
|
|
167
167
|
args[key] = true
|
package/src/params.test.js
CHANGED
|
@@ -52,3 +52,17 @@ test('parseArgs preserves query JSON supplied after --json', () => {
|
|
|
52
52
|
{ _: ['query'], json: '{"intent":"author_search","platform":"douyin"}' }
|
|
53
53
|
)
|
|
54
54
|
})
|
|
55
|
+
|
|
56
|
+
test('parseArgs maps --json-file to the property used by query', () => {
|
|
57
|
+
assert.deepEqual(
|
|
58
|
+
parseArgs(['query', '--json-file', 'request.json']),
|
|
59
|
+
{ _: ['query'], jsonFile: 'request.json' }
|
|
60
|
+
)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('parseArgs preserves query JSON split into multiple argv fragments', () => {
|
|
64
|
+
assert.deepEqual(
|
|
65
|
+
parseArgs(['query', '--json', '{"intent":', '"author_search",', '"platform":"douyin"}']),
|
|
66
|
+
{ _: ['query'], json: '{"intent":"author_search","platform":"douyin"}' }
|
|
67
|
+
)
|
|
68
|
+
})
|