@gutenye/script.js 2.7.3 → 2.8.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 +1 -1
- package/src/completion.ts +2 -2
- package/src/parseArgv.ts +4 -0
package/package.json
CHANGED
package/src/completion.ts
CHANGED
|
@@ -61,9 +61,9 @@ export function buildSpec(command: Command): CarapaceSpec {
|
|
|
61
61
|
spec.flags = spec.flags || {}
|
|
62
62
|
let flag = [opt.short, opt.long].filter(Boolean).join(', ')
|
|
63
63
|
const values = resolveCompletion(opt.completion)
|
|
64
|
-
if (
|
|
64
|
+
if (values.length > 0) flag += '='
|
|
65
|
+
else if (opt.required) flag += '='
|
|
65
66
|
else if (opt.optional) flag += '=?'
|
|
66
|
-
else if (values.length > 0) flag += '='
|
|
67
67
|
spec.flags[flag] = opt.description
|
|
68
68
|
|
|
69
69
|
if (values.length > 0) {
|
package/src/parseArgv.ts
CHANGED
|
@@ -7,6 +7,7 @@ export function parseArgv(
|
|
|
7
7
|
registeredOptions: Option[],
|
|
8
8
|
): { positionals: any[]; options: Record<string, any> } {
|
|
9
9
|
const options: Record<string, any> = {}
|
|
10
|
+
const provided = new Set<string>()
|
|
10
11
|
const rawPositionals: string[] = []
|
|
11
12
|
|
|
12
13
|
for (const opt of registeredOptions) {
|
|
@@ -40,6 +41,7 @@ export function parseArgv(
|
|
|
40
41
|
|
|
41
42
|
const opt = findOption(flag, registeredOptions)
|
|
42
43
|
if (opt) {
|
|
44
|
+
provided.add(opt.attributeName)
|
|
43
45
|
if (opt.negate) {
|
|
44
46
|
options[opt.attributeName] = false
|
|
45
47
|
} else if (opt.required) {
|
|
@@ -68,6 +70,8 @@ export function parseArgv(
|
|
|
68
70
|
i++
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
options.$has = (key: string) => provided.has(key)
|
|
74
|
+
|
|
71
75
|
const positionals: any[] = []
|
|
72
76
|
let posIdx = 0
|
|
73
77
|
for (const arg of registeredArgs) {
|