@autor3search/javascript 0.2.2 → 0.2.3
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 +1 -1
- package/src/cli/cmd-baseline.js +7 -6
- package/src/cli/cmd-eval.js +8 -7
- package/src/cli/cmd-status.js +3 -2
- package/src/cli/cmd-stop.js +8 -7
- package/src/cli/context.js +22 -5
package/package.json
CHANGED
package/src/cli/cmd-baseline.js
CHANGED
|
@@ -28,13 +28,14 @@ import {
|
|
|
28
28
|
import { expandSingleDashFlags, loadRepoConfig, resolveRepo } from './context.js'
|
|
29
29
|
|
|
30
30
|
export async function runBaseline(args, io) {
|
|
31
|
+
const options = {
|
|
32
|
+
C: { type: 'string', default: '.' },
|
|
33
|
+
tag: { type: 'string', default: defaultTag() },
|
|
34
|
+
force: { type: 'boolean', default: false },
|
|
35
|
+
}
|
|
31
36
|
const { values } = parseArgs({
|
|
32
|
-
args: expandSingleDashFlags(args,
|
|
33
|
-
options
|
|
34
|
-
C: { type: 'string', default: '.' },
|
|
35
|
-
tag: { type: 'string', default: defaultTag() },
|
|
36
|
-
force: { type: 'boolean', default: false },
|
|
37
|
-
},
|
|
37
|
+
args: expandSingleDashFlags(args, options),
|
|
38
|
+
options,
|
|
38
39
|
allowPositionals: false,
|
|
39
40
|
})
|
|
40
41
|
|
package/src/cli/cmd-eval.js
CHANGED
|
@@ -29,14 +29,15 @@ const FORCE_POLL_MS = 500
|
|
|
29
29
|
* @returns {Promise<number>}
|
|
30
30
|
*/
|
|
31
31
|
export async function runEval(args, io) {
|
|
32
|
+
const options = {
|
|
33
|
+
C: { type: 'string', default: '.' },
|
|
34
|
+
json: { type: 'boolean', default: false },
|
|
35
|
+
desc: { type: 'string', default: '' },
|
|
36
|
+
'no-log': { type: 'boolean', default: false },
|
|
37
|
+
}
|
|
32
38
|
const { values } = parseArgs({
|
|
33
|
-
args: expandSingleDashFlags(args,
|
|
34
|
-
options
|
|
35
|
-
C: { type: 'string', default: '.' },
|
|
36
|
-
json: { type: 'boolean', default: false },
|
|
37
|
-
desc: { type: 'string', default: '' },
|
|
38
|
-
'no-log': { type: 'boolean', default: false },
|
|
39
|
-
},
|
|
39
|
+
args: expandSingleDashFlags(args, options),
|
|
40
|
+
options,
|
|
40
41
|
allowPositionals: false,
|
|
41
42
|
})
|
|
42
43
|
|
package/src/cli/cmd-status.js
CHANGED
|
@@ -17,9 +17,10 @@ import { expandSingleDashFlags, resolveRun } from './context.js'
|
|
|
17
17
|
* @returns {Promise<number>}
|
|
18
18
|
*/
|
|
19
19
|
export async function runStatus(args, io) {
|
|
20
|
+
const options = { C: { type: 'string', default: '.' }, tag: { type: 'string' } }
|
|
20
21
|
const { values } = parseArgs({
|
|
21
|
-
args: expandSingleDashFlags(args,
|
|
22
|
-
options
|
|
22
|
+
args: expandSingleDashFlags(args, options),
|
|
23
|
+
options,
|
|
23
24
|
allowPositionals: false,
|
|
24
25
|
})
|
|
25
26
|
|
package/src/cli/cmd-stop.js
CHANGED
|
@@ -23,14 +23,15 @@ import { expandSingleDashFlags, resolveRun } from './context.js'
|
|
|
23
23
|
* @returns {Promise<number>}
|
|
24
24
|
*/
|
|
25
25
|
export async function runStop(args, io) {
|
|
26
|
+
const options = {
|
|
27
|
+
C: { type: 'string', default: '.' },
|
|
28
|
+
tag: { type: 'string' },
|
|
29
|
+
clear: { type: 'boolean', default: false },
|
|
30
|
+
force: { type: 'boolean', default: false },
|
|
31
|
+
}
|
|
26
32
|
const { values } = parseArgs({
|
|
27
|
-
args: expandSingleDashFlags(args,
|
|
28
|
-
options
|
|
29
|
-
C: { type: 'string', default: '.' },
|
|
30
|
-
tag: { type: 'string' },
|
|
31
|
-
clear: { type: 'boolean', default: false },
|
|
32
|
-
force: { type: 'boolean', default: false },
|
|
33
|
-
},
|
|
33
|
+
args: expandSingleDashFlags(args, options),
|
|
34
|
+
options,
|
|
34
35
|
allowPositionals: false,
|
|
35
36
|
})
|
|
36
37
|
|
package/src/cli/context.js
CHANGED
|
@@ -24,20 +24,37 @@ import { join } from 'node:path'
|
|
|
24
24
|
* Only an exact whole-token match is rewritten, so a VALUE that happens to
|
|
25
25
|
* look like a flag (`-desc "-tag is confusing"`) is left alone.
|
|
26
26
|
*
|
|
27
|
+
* The parseArgs OPTIONS are the input, not a list of names, and that is
|
|
28
|
+
* load-bearing. A hand-kept list is free to fall out of step with the
|
|
29
|
+
* declaration beside it, and did: `stop` accepted `-tag` but not the `-force`
|
|
30
|
+
* the README documents, so `stop -force` failed with "Unknown option '-f'"
|
|
31
|
+
* until this was derived instead. Deriving it means a flag cannot be
|
|
32
|
+
* documented, declared, and still unparseable.
|
|
33
|
+
*
|
|
34
|
+
* Whether a flag consumes the token after it comes from its declared `type`.
|
|
35
|
+
* A boolean takes no value, so the next token is another flag and must still
|
|
36
|
+
* be expanded — skipping it is what made `-force -tag t` die on "Unknown
|
|
37
|
+
* option '-t'". Single-character names are left alone because parseArgs
|
|
38
|
+
* already accepts them in single-dash form; `-C` must stay `-C`.
|
|
39
|
+
*
|
|
27
40
|
* @param {string[]} args
|
|
28
|
-
* @param {string
|
|
41
|
+
* @param {Record<string, {type: string}>} options the same parseArgs options the caller parses with
|
|
29
42
|
* @returns {string[]}
|
|
30
43
|
*/
|
|
31
|
-
export function expandSingleDashFlags(args,
|
|
32
|
-
const
|
|
44
|
+
export function expandSingleDashFlags(args, options) {
|
|
45
|
+
const expandable = new Map(
|
|
46
|
+
Object.entries(options)
|
|
47
|
+
.filter(([name]) => name.length > 1)
|
|
48
|
+
.map(([name, opt]) => [`-${name}`, opt.type !== 'boolean']),
|
|
49
|
+
)
|
|
33
50
|
let expectingValue = false
|
|
34
51
|
return args.map((token) => {
|
|
35
52
|
if (expectingValue) {
|
|
36
53
|
expectingValue = false
|
|
37
54
|
return token
|
|
38
55
|
}
|
|
39
|
-
if (
|
|
40
|
-
expectingValue =
|
|
56
|
+
if (expandable.has(token)) {
|
|
57
|
+
expectingValue = expandable.get(token)
|
|
41
58
|
return `--${token.slice(1)}`
|
|
42
59
|
}
|
|
43
60
|
return token
|