@optique/core 0.9.0 → 0.9.2

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.
@@ -815,8 +815,21 @@ function command(name, parser, options = {}) {
815
815
  success: false,
816
816
  error: options.errors?.notFound ?? require_message.message`Command ${require_message.optionName(name)} was not matched.`
817
817
  };
818
- else if (state[0] === "matched") return parser.complete(parser.initialState);
819
- else if (state[0] === "parsing") return parser.complete(state[1]);
818
+ else if (state[0] === "matched") {
819
+ const parseResultOrPromise = parser.parse({
820
+ buffer: [],
821
+ optionsTerminated: false,
822
+ usage: [],
823
+ state: parser.initialState
824
+ });
825
+ if (isAsync) return parseResultOrPromise.then((parseResult$1) => {
826
+ if (parseResult$1.success) return parser.complete(parseResult$1.next.state);
827
+ return parser.complete(parser.initialState);
828
+ });
829
+ const parseResult = parseResultOrPromise;
830
+ if (parseResult.success) return parser.complete(parseResult.next.state);
831
+ return parser.complete(parser.initialState);
832
+ } else if (state[0] === "parsing") return parser.complete(state[1]);
820
833
  return {
821
834
  success: false,
822
835
  error: options.errors?.invalidState ?? require_message.message`Invalid command state during completion.`
@@ -827,21 +840,23 @@ function command(name, parser, options = {}) {
827
840
  return suggestCommandSync(context, prefix, name, parser, options);
828
841
  },
829
842
  getDocFragments(state, defaultValue) {
830
- if (options.hidden) return {
831
- fragments: [],
832
- description: options.description
833
- };
834
- if (state.kind === "unavailable" || typeof state.state === "undefined") return {
835
- description: options.description,
836
- fragments: [{
837
- type: "entry",
838
- term: {
839
- type: "command",
840
- name
841
- },
842
- description: options.brief ?? options.description
843
- }]
844
- };
843
+ if (state.kind === "unavailable" || typeof state.state === "undefined") {
844
+ if (options.hidden) return {
845
+ fragments: [],
846
+ description: options.description
847
+ };
848
+ return {
849
+ description: options.description,
850
+ fragments: [{
851
+ type: "entry",
852
+ term: {
853
+ type: "command",
854
+ name
855
+ },
856
+ description: options.brief ?? options.description
857
+ }]
858
+ };
859
+ }
845
860
  const innerState = state.state[0] === "parsing" ? {
846
861
  kind: "available",
847
862
  state: state.state[1]
@@ -815,8 +815,21 @@ function command(name, parser, options = {}) {
815
815
  success: false,
816
816
  error: options.errors?.notFound ?? message`Command ${optionName(name)} was not matched.`
817
817
  };
818
- else if (state[0] === "matched") return parser.complete(parser.initialState);
819
- else if (state[0] === "parsing") return parser.complete(state[1]);
818
+ else if (state[0] === "matched") {
819
+ const parseResultOrPromise = parser.parse({
820
+ buffer: [],
821
+ optionsTerminated: false,
822
+ usage: [],
823
+ state: parser.initialState
824
+ });
825
+ if (isAsync) return parseResultOrPromise.then((parseResult$1) => {
826
+ if (parseResult$1.success) return parser.complete(parseResult$1.next.state);
827
+ return parser.complete(parser.initialState);
828
+ });
829
+ const parseResult = parseResultOrPromise;
830
+ if (parseResult.success) return parser.complete(parseResult.next.state);
831
+ return parser.complete(parser.initialState);
832
+ } else if (state[0] === "parsing") return parser.complete(state[1]);
820
833
  return {
821
834
  success: false,
822
835
  error: options.errors?.invalidState ?? message`Invalid command state during completion.`
@@ -827,21 +840,23 @@ function command(name, parser, options = {}) {
827
840
  return suggestCommandSync(context, prefix, name, parser, options);
828
841
  },
829
842
  getDocFragments(state, defaultValue) {
830
- if (options.hidden) return {
831
- fragments: [],
832
- description: options.description
833
- };
834
- if (state.kind === "unavailable" || typeof state.state === "undefined") return {
835
- description: options.description,
836
- fragments: [{
837
- type: "entry",
838
- term: {
839
- type: "command",
840
- name
841
- },
842
- description: options.brief ?? options.description
843
- }]
844
- };
843
+ if (state.kind === "unavailable" || typeof state.state === "undefined") {
844
+ if (options.hidden) return {
845
+ fragments: [],
846
+ description: options.description
847
+ };
848
+ return {
849
+ description: options.description,
850
+ fragments: [{
851
+ type: "entry",
852
+ term: {
853
+ type: "command",
854
+ name
855
+ },
856
+ description: options.brief ?? options.description
857
+ }]
858
+ };
859
+ }
845
860
  const innerState = state.state[0] === "parsing" ? {
846
861
  kind: "available",
847
862
  state: state.state[1]
package/dist/usage.cjs CHANGED
@@ -123,6 +123,8 @@ function formatUsage(programName, usage, options = {}) {
123
123
  if (usage.length > 0 && usage.slice(0, -1).every((t) => t.type === "command") && lastTerm.type === "exclusive" && lastTerm.terms.every((t) => t.length > 0 && (t[0].type === "command" || t[0].type === "option" || t[0].type === "argument" || t[0].type === "optional" && t[0].terms.length === 1 && (t[0].terms[0].type === "command" || t[0].terms[0].type === "option" || t[0].terms[0].type === "argument")))) {
124
124
  const lines = [];
125
125
  for (let command of lastTerm.terms) {
126
+ const firstTerm = command[0];
127
+ if (firstTerm?.type === "command" && firstTerm.hidden) continue;
126
128
  if (usage.length > 1) command = [...usage.slice(0, -1), ...command];
127
129
  lines.push(formatUsage(programName, command, options));
128
130
  }
package/dist/usage.js CHANGED
@@ -122,6 +122,8 @@ function formatUsage(programName, usage, options = {}) {
122
122
  if (usage.length > 0 && usage.slice(0, -1).every((t) => t.type === "command") && lastTerm.type === "exclusive" && lastTerm.terms.every((t) => t.length > 0 && (t[0].type === "command" || t[0].type === "option" || t[0].type === "argument" || t[0].type === "optional" && t[0].terms.length === 1 && (t[0].terms[0].type === "command" || t[0].terms[0].type === "option" || t[0].terms[0].type === "argument")))) {
123
123
  const lines = [];
124
124
  for (let command of lastTerm.terms) {
125
+ const firstTerm = command[0];
126
+ if (firstTerm?.type === "command" && firstTerm.hidden) continue;
125
127
  if (usage.length > 1) command = [...usage.slice(0, -1), ...command];
126
128
  lines.push(formatUsage(programName, command, options));
127
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",