@optique/core 0.8.3 → 0.8.5
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/dist/constructs.cjs +10 -2
- package/dist/constructs.js +10 -2
- package/dist/facade.cjs +3 -3
- package/dist/facade.js +3 -3
- package/dist/parser.cjs +25 -8
- package/dist/parser.js +25 -8
- package/dist/primitives.cjs +4 -1
- package/dist/primitives.js +4 -1
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -760,8 +760,16 @@ function merge(...args) {
|
|
|
760
760
|
return require_suggestion.deduplicateSuggestions(suggestions);
|
|
761
761
|
},
|
|
762
762
|
getDocFragments(state, _defaultValue) {
|
|
763
|
-
const fragments = parsers.flatMap((p) => {
|
|
764
|
-
|
|
763
|
+
const fragments = parsers.flatMap((p, i) => {
|
|
764
|
+
let parserState;
|
|
765
|
+
if (p.initialState === void 0) {
|
|
766
|
+
const key = `__parser_${i}`;
|
|
767
|
+
if (state.kind === "available" && state.state && typeof state.state === "object" && key in state.state) parserState = {
|
|
768
|
+
kind: "available",
|
|
769
|
+
state: state.state[key]
|
|
770
|
+
};
|
|
771
|
+
else parserState = { kind: "unavailable" };
|
|
772
|
+
} else parserState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
765
773
|
kind: "available",
|
|
766
774
|
state: state.state
|
|
767
775
|
};
|
package/dist/constructs.js
CHANGED
|
@@ -760,8 +760,16 @@ function merge(...args) {
|
|
|
760
760
|
return deduplicateSuggestions(suggestions);
|
|
761
761
|
},
|
|
762
762
|
getDocFragments(state, _defaultValue) {
|
|
763
|
-
const fragments = parsers.flatMap((p) => {
|
|
764
|
-
|
|
763
|
+
const fragments = parsers.flatMap((p, i) => {
|
|
764
|
+
let parserState;
|
|
765
|
+
if (p.initialState === void 0) {
|
|
766
|
+
const key = `__parser_${i}`;
|
|
767
|
+
if (state.kind === "available" && state.state && typeof state.state === "object" && key in state.state) parserState = {
|
|
768
|
+
kind: "available",
|
|
769
|
+
state: state.state[key]
|
|
770
|
+
};
|
|
771
|
+
else parserState = { kind: "unavailable" };
|
|
772
|
+
} else parserState = state.kind === "unavailable" ? { kind: "unavailable" } : {
|
|
765
773
|
kind: "available",
|
|
766
774
|
state: state.state
|
|
767
775
|
};
|
package/dist/facade.cjs
CHANGED
|
@@ -13,7 +13,7 @@ const require_parser = require('./parser.cjs');
|
|
|
13
13
|
* Creates help parsers based on the specified mode.
|
|
14
14
|
*/
|
|
15
15
|
function createHelpParser(mode) {
|
|
16
|
-
const helpCommand = require_primitives.command("help", require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "COMMAND" }))), { description: require_message.message`Show help information.` });
|
|
16
|
+
const helpCommand = require_primitives.command("help", require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "COMMAND" }), { description: require_message.message`Command name to show help for.` })), { description: require_message.message`Show help information.` });
|
|
17
17
|
const helpOption = require_primitives.flag("--help", { description: require_message.message`Show help information.` });
|
|
18
18
|
switch (mode) {
|
|
19
19
|
case "command": return {
|
|
@@ -98,14 +98,14 @@ function createCompletionParser(mode, programName, availableShells, name = "both
|
|
|
98
98
|
completionCommand: null,
|
|
99
99
|
completionOption: require_constructs.object({
|
|
100
100
|
shell: completionOption,
|
|
101
|
-
args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }))), [])
|
|
101
|
+
args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }), { description: require_message.message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
|
|
102
102
|
})
|
|
103
103
|
};
|
|
104
104
|
case "both": return {
|
|
105
105
|
completionCommand,
|
|
106
106
|
completionOption: require_constructs.object({
|
|
107
107
|
shell: completionOption,
|
|
108
|
-
args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }))), [])
|
|
108
|
+
args: require_modifiers.withDefault(require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "ARG" }), { description: require_message.message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
|
|
109
109
|
})
|
|
110
110
|
};
|
|
111
111
|
}
|
package/dist/facade.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getDocPage, parse, suggest } from "./parser.js";
|
|
|
13
13
|
* Creates help parsers based on the specified mode.
|
|
14
14
|
*/
|
|
15
15
|
function createHelpParser(mode) {
|
|
16
|
-
const helpCommand = command("help", multiple(argument(string({ metavar: "COMMAND" }))), { description: message`Show help information.` });
|
|
16
|
+
const helpCommand = command("help", multiple(argument(string({ metavar: "COMMAND" }), { description: message`Command name to show help for.` })), { description: message`Show help information.` });
|
|
17
17
|
const helpOption = flag("--help", { description: message`Show help information.` });
|
|
18
18
|
switch (mode) {
|
|
19
19
|
case "command": return {
|
|
@@ -98,14 +98,14 @@ function createCompletionParser(mode, programName, availableShells, name = "both
|
|
|
98
98
|
completionCommand: null,
|
|
99
99
|
completionOption: object({
|
|
100
100
|
shell: completionOption,
|
|
101
|
-
args: withDefault(multiple(argument(string({ metavar: "ARG" }))), [])
|
|
101
|
+
args: withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
|
|
102
102
|
})
|
|
103
103
|
};
|
|
104
104
|
case "both": return {
|
|
105
105
|
completionCommand,
|
|
106
106
|
completionOption: object({
|
|
107
107
|
shell: completionOption,
|
|
108
|
-
args: withDefault(multiple(argument(string({ metavar: "ARG" }))), [])
|
|
108
|
+
args: withDefault(multiple(argument(string({ metavar: "ARG" }), { description: message`Command line arguments for completion suggestions (used by shell integration; you usually don't need to provide this).` })), [])
|
|
109
109
|
})
|
|
110
110
|
};
|
|
111
111
|
}
|
package/dist/parser.cjs
CHANGED
|
@@ -95,6 +95,26 @@ function suggest(parser, args) {
|
|
|
95
95
|
return Array.from(parser.suggest(context, prefix));
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
+
* Recursively searches for a command within nested exclusive usage terms.
|
|
99
|
+
* When the command is found, returns the expanded usage terms for that command.
|
|
100
|
+
*
|
|
101
|
+
* @param term The usage term to search in
|
|
102
|
+
* @param commandName The command name to find
|
|
103
|
+
* @returns The expanded usage terms if found, null otherwise
|
|
104
|
+
*/
|
|
105
|
+
function findCommandInExclusive(term, commandName) {
|
|
106
|
+
if (term.type !== "exclusive") return null;
|
|
107
|
+
for (const termGroup of term.terms) {
|
|
108
|
+
const firstTerm = termGroup[0];
|
|
109
|
+
if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
|
|
110
|
+
if (firstTerm?.type === "exclusive") {
|
|
111
|
+
const found = findCommandInExclusive(firstTerm, commandName);
|
|
112
|
+
if (found) return [...found, ...termGroup.slice(1)];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
98
118
|
* Generates a documentation page for a parser based on its current state after
|
|
99
119
|
* attempting to parse the provided arguments. This function is useful for
|
|
100
120
|
* creating help documentation that reflects the current parsing context.
|
|
@@ -157,14 +177,11 @@ function getDocPage(parser, args = []) {
|
|
|
157
177
|
if (i >= usage.length) break;
|
|
158
178
|
const term = usage[i];
|
|
159
179
|
if (term.type === "exclusive") {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
if (usage[i] === term) i++;
|
|
180
|
+
const found = findCommandInExclusive(term, arg);
|
|
181
|
+
if (found) {
|
|
182
|
+
usage.splice(i, 1, ...found);
|
|
183
|
+
i += found.length;
|
|
184
|
+
} else i++;
|
|
168
185
|
} else i++;
|
|
169
186
|
}
|
|
170
187
|
return {
|
package/dist/parser.js
CHANGED
|
@@ -95,6 +95,26 @@ function suggest(parser, args) {
|
|
|
95
95
|
return Array.from(parser.suggest(context, prefix));
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
+
* Recursively searches for a command within nested exclusive usage terms.
|
|
99
|
+
* When the command is found, returns the expanded usage terms for that command.
|
|
100
|
+
*
|
|
101
|
+
* @param term The usage term to search in
|
|
102
|
+
* @param commandName The command name to find
|
|
103
|
+
* @returns The expanded usage terms if found, null otherwise
|
|
104
|
+
*/
|
|
105
|
+
function findCommandInExclusive(term, commandName) {
|
|
106
|
+
if (term.type !== "exclusive") return null;
|
|
107
|
+
for (const termGroup of term.terms) {
|
|
108
|
+
const firstTerm = termGroup[0];
|
|
109
|
+
if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
|
|
110
|
+
if (firstTerm?.type === "exclusive") {
|
|
111
|
+
const found = findCommandInExclusive(firstTerm, commandName);
|
|
112
|
+
if (found) return [...found, ...termGroup.slice(1)];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
98
118
|
* Generates a documentation page for a parser based on its current state after
|
|
99
119
|
* attempting to parse the provided arguments. This function is useful for
|
|
100
120
|
* creating help documentation that reflects the current parsing context.
|
|
@@ -157,14 +177,11 @@ function getDocPage(parser, args = []) {
|
|
|
157
177
|
if (i >= usage.length) break;
|
|
158
178
|
const term = usage[i];
|
|
159
179
|
if (term.type === "exclusive") {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
if (usage[i] === term) i++;
|
|
180
|
+
const found = findCommandInExclusive(term, arg);
|
|
181
|
+
if (found) {
|
|
182
|
+
usage.splice(i, 1, ...found);
|
|
183
|
+
i += found.length;
|
|
184
|
+
} else i++;
|
|
168
185
|
} else i++;
|
|
169
186
|
}
|
|
170
187
|
return {
|
package/dist/primitives.cjs
CHANGED
|
@@ -710,7 +710,10 @@ function command(name, parser, options = {}) {
|
|
|
710
710
|
const innerState = state.state[0] === "parsing" ? {
|
|
711
711
|
kind: "available",
|
|
712
712
|
state: state.state[1]
|
|
713
|
-
} : {
|
|
713
|
+
} : {
|
|
714
|
+
kind: "available",
|
|
715
|
+
state: parser.initialState
|
|
716
|
+
};
|
|
714
717
|
const innerFragments = parser.getDocFragments(innerState, defaultValue);
|
|
715
718
|
return {
|
|
716
719
|
...innerFragments,
|
package/dist/primitives.js
CHANGED
|
@@ -710,7 +710,10 @@ function command(name, parser, options = {}) {
|
|
|
710
710
|
const innerState = state.state[0] === "parsing" ? {
|
|
711
711
|
kind: "available",
|
|
712
712
|
state: state.state[1]
|
|
713
|
-
} : {
|
|
713
|
+
} : {
|
|
714
|
+
kind: "available",
|
|
715
|
+
state: parser.initialState
|
|
716
|
+
};
|
|
714
717
|
const innerFragments = parser.getDocFragments(innerState, defaultValue);
|
|
715
718
|
return {
|
|
716
719
|
...innerFragments,
|