@optique/core 1.0.0-dev.427 → 1.0.0-dev.429

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/parser.d.cts CHANGED
@@ -4,7 +4,7 @@ import { Usage } from "./usage.cjs";
4
4
  import { DocFragments, DocPage } from "./doc.cjs";
5
5
  import { DependencyRegistryLike } from "./registry-types.cjs";
6
6
  import { ValueParserResult } from "./valueparser.cjs";
7
- import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
7
+ import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
8
8
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.cjs";
10
10
 
@@ -534,4 +534,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: rea
534
534
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
535
535
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
536
536
  //#endregion
537
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
537
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
package/dist/parser.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Usage } from "./usage.js";
4
4
  import { DocFragments, DocPage } from "./doc.js";
5
5
  import { DependencyRegistryLike } from "./registry-types.js";
6
6
  import { ValueParserResult } from "./valueparser.js";
7
- import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
7
+ import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
8
8
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
10
10
 
@@ -534,4 +534,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: rea
534
534
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
535
535
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
536
536
  //#endregion
537
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
537
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
@@ -313,13 +313,13 @@ function option(...args) {
313
313
  terms: [{
314
314
  type: "option",
315
315
  names: optionNames$1,
316
- ...options.hidden && { hidden: true }
316
+ ...options.hidden != null && { hidden: options.hidden }
317
317
  }]
318
318
  } : {
319
319
  type: "option",
320
320
  names: optionNames$1,
321
321
  metavar: valueParser.metavar,
322
- ...options.hidden && { hidden: true }
322
+ ...options.hidden != null && { hidden: options.hidden }
323
323
  }],
324
324
  initialState: valueParser == null ? {
325
325
  success: true,
@@ -505,11 +505,11 @@ function option(...args) {
505
505
  };
506
506
  },
507
507
  suggest(context, prefix) {
508
- if (isAsync) return suggestOptionAsync(optionNames$1, valueParser, options.hidden ?? false, context, prefix);
509
- return suggestOptionSync(optionNames$1, valueParser, options.hidden ?? false, context, prefix);
508
+ if (isAsync) return suggestOptionAsync(optionNames$1, valueParser, require_usage.isSuggestionHidden(options.hidden), context, prefix);
509
+ return suggestOptionSync(optionNames$1, valueParser, require_usage.isSuggestionHidden(options.hidden), context, prefix);
510
510
  },
511
511
  getDocFragments(_state, defaultValue) {
512
- if (options.hidden) return {
512
+ if (require_usage.isDocHidden(options.hidden)) return {
513
513
  fragments: [],
514
514
  description: options.description
515
515
  };
@@ -583,7 +583,7 @@ function flag(...args) {
583
583
  usage: [{
584
584
  type: "option",
585
585
  names: optionNames$1,
586
- ...options.hidden && { hidden: true }
586
+ ...options.hidden != null && { hidden: options.hidden }
587
587
  }],
588
588
  initialState: void 0,
589
589
  parse(context) {
@@ -690,7 +690,7 @@ function flag(...args) {
690
690
  };
691
691
  },
692
692
  suggest(_context, prefix) {
693
- if (options.hidden) return [];
693
+ if (require_usage.isSuggestionHidden(options.hidden)) return [];
694
694
  const suggestions = [];
695
695
  if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/")) {
696
696
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
@@ -704,7 +704,7 @@ function flag(...args) {
704
704
  return suggestions;
705
705
  },
706
706
  getDocFragments(_state, _defaultValue) {
707
- if (options.hidden) return {
707
+ if (require_usage.isDocHidden(options.hidden)) return {
708
708
  fragments: [],
709
709
  description: options.description
710
710
  };
@@ -745,7 +745,7 @@ function argument(valueParser, options = {}) {
745
745
  const term = {
746
746
  type: "argument",
747
747
  metavar: valueParser.metavar,
748
- ...options.hidden && { hidden: true }
748
+ ...options.hidden != null && { hidden: options.hidden }
749
749
  };
750
750
  const result = {
751
751
  $mode: valueParser.$mode,
@@ -833,11 +833,11 @@ function argument(valueParser, options = {}) {
833
833
  };
834
834
  },
835
835
  suggest(context, prefix) {
836
- if (isAsync) return suggestArgumentAsync(valueParser, options.hidden ?? false, prefix, context.dependencyRegistry);
837
- return suggestArgumentSync(valueParser, options.hidden ?? false, prefix, context.dependencyRegistry);
836
+ if (isAsync) return suggestArgumentAsync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
837
+ return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
838
838
  },
839
839
  getDocFragments(_state, defaultValue) {
840
- if (options.hidden) return {
840
+ if (require_usage.isDocHidden(options.hidden)) return {
841
841
  fragments: [],
842
842
  description: options.description
843
843
  };
@@ -861,7 +861,7 @@ function argument(valueParser, options = {}) {
861
861
  return result;
862
862
  }
863
863
  function* suggestCommandSync(context, prefix, name, parser, options) {
864
- if (options.hidden) return;
864
+ if (require_usage.isSuggestionHidden(options.hidden)) return;
865
865
  if (context.state === void 0) {
866
866
  if (name.startsWith(prefix)) yield {
867
867
  kind: "literal",
@@ -878,7 +878,7 @@ function* suggestCommandSync(context, prefix, name, parser, options) {
878
878
  }, prefix);
879
879
  }
880
880
  async function* suggestCommandAsync(context, prefix, name, parser, options) {
881
- if (options.hidden) return;
881
+ if (require_usage.isSuggestionHidden(options.hidden)) return;
882
882
  if (context.state === void 0) {
883
883
  if (name.startsWith(prefix)) yield {
884
884
  kind: "literal",
@@ -923,7 +923,7 @@ function command(name, parser, options = {}) {
923
923
  usage: [{
924
924
  type: "command",
925
925
  name,
926
- ...options.hidden && { hidden: true }
926
+ ...options.hidden != null && { hidden: options.hidden }
927
927
  }, ...parser.usage],
928
928
  initialState: void 0,
929
929
  parse(context) {
@@ -1023,7 +1023,7 @@ function command(name, parser, options = {}) {
1023
1023
  },
1024
1024
  getDocFragments(state, defaultValue) {
1025
1025
  if (state.kind === "unavailable" || typeof state.state === "undefined") {
1026
- if (options.hidden) return {
1026
+ if (require_usage.isDocHidden(options.hidden)) return {
1027
1027
  fragments: [],
1028
1028
  description: options.description
1029
1029
  };
@@ -1117,7 +1117,7 @@ function passThrough(options = {}) {
1117
1117
  priority: -10,
1118
1118
  usage: [{
1119
1119
  type: "passthrough",
1120
- ...options.hidden && { hidden: true }
1120
+ ...options.hidden != null && { hidden: options.hidden }
1121
1121
  }],
1122
1122
  initialState: [],
1123
1123
  parse(context) {
@@ -1215,7 +1215,7 @@ function passThrough(options = {}) {
1215
1215
  return [];
1216
1216
  },
1217
1217
  getDocFragments(_state, _defaultValue) {
1218
- if (options.hidden) return {
1218
+ if (require_usage.isDocHidden(options.hidden)) return {
1219
1219
  fragments: [],
1220
1220
  description: options.description
1221
1221
  };
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.cjs";
2
- import { OptionName } from "./usage.cjs";
2
+ import { HiddenVisibility, OptionName } from "./usage.cjs";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.cjs";
4
4
  import { DeferredParseState, PendingDependencySourceState } from "./dependency.cjs";
5
5
  import { Mode, Parser } from "./parser.cjs";
@@ -47,12 +47,15 @@ interface OptionOptions {
47
47
  */
48
48
  readonly description?: Message;
49
49
  /**
50
- * When `true`, hides the option from help text, shell completion
51
- * suggestions, and "Did you mean?" error suggestions. The option
52
- * remains fully functional for parsing.
50
+ * Controls option visibility:
51
+ *
52
+ * - `true`: hide from usage, docs, and suggestions
53
+ * - `"usage"`: hide from usage only
54
+ * - `"doc"`: hide from docs only
55
+ *
53
56
  * @since 0.9.0
54
57
  */
55
- readonly hidden?: boolean;
58
+ readonly hidden?: HiddenVisibility;
56
59
  /**
57
60
  * Error message customization options.
58
61
  * @since 0.5.0
@@ -155,12 +158,15 @@ interface FlagOptions {
155
158
  */
156
159
  readonly description?: Message;
157
160
  /**
158
- * When `true`, hides the flag from help text, shell completion
159
- * suggestions, and "Did you mean?" error suggestions. The flag
160
- * remains fully functional for parsing.
161
+ * Controls flag visibility:
162
+ *
163
+ * - `true`: hide from usage, docs, and suggestions
164
+ * - `"usage"`: hide from usage only
165
+ * - `"doc"`: hide from docs only
166
+ *
161
167
  * @since 0.9.0
162
168
  */
163
- readonly hidden?: boolean;
169
+ readonly hidden?: HiddenVisibility;
164
170
  /**
165
171
  * Error message customization options.
166
172
  * @since 0.5.0
@@ -241,12 +247,15 @@ interface ArgumentOptions {
241
247
  */
242
248
  readonly description?: Message;
243
249
  /**
244
- * When `true`, hides the argument from help text, shell completion
245
- * suggestions, and error suggestions. The argument remains fully
246
- * functional for parsing.
250
+ * Controls argument visibility:
251
+ *
252
+ * - `true`: hide from usage, docs, and suggestions
253
+ * - `"usage"`: hide from usage only
254
+ * - `"doc"`: hide from docs only
255
+ *
247
256
  * @since 0.9.0
248
257
  */
249
- readonly hidden?: boolean;
258
+ readonly hidden?: HiddenVisibility;
250
259
  /**
251
260
  * Error message customization options.
252
261
  * @since 0.5.0
@@ -312,12 +321,15 @@ interface CommandOptions {
312
321
  */
313
322
  readonly footer?: Message;
314
323
  /**
315
- * When `true`, hides the command from help text, shell completion
316
- * suggestions, and "Did you mean?" error suggestions. The command
317
- * remains fully functional for parsing.
324
+ * Controls command visibility:
325
+ *
326
+ * - `true`: hide from usage, docs, and suggestions
327
+ * - `"usage"`: hide from usage only
328
+ * - `"doc"`: hide from docs only
329
+ *
318
330
  * @since 0.9.0
319
331
  */
320
- readonly hidden?: boolean;
332
+ readonly hidden?: HiddenVisibility;
321
333
  /**
322
334
  * Error messages customization.
323
335
  * @since 0.5.0
@@ -396,11 +408,15 @@ interface PassThroughOptions {
396
408
  */
397
409
  readonly description?: Message;
398
410
  /**
399
- * When `true`, hides the pass-through from help text and shell
400
- * completion suggestions. The parser remains fully functional.
411
+ * Controls pass-through visibility:
412
+ *
413
+ * - `true`: hide from usage, docs, and suggestions
414
+ * - `"usage"`: hide from usage only
415
+ * - `"doc"`: hide from docs only
416
+ *
401
417
  * @since 0.9.0
402
418
  */
403
- readonly hidden?: boolean;
419
+ readonly hidden?: HiddenVisibility;
404
420
  }
405
421
  /**
406
422
  * Creates a parser that collects unrecognized options and passes them through.
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.js";
2
- import { OptionName } from "./usage.js";
2
+ import { HiddenVisibility, OptionName } from "./usage.js";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.js";
4
4
  import { DeferredParseState, PendingDependencySourceState } from "./dependency.js";
5
5
  import { Mode, Parser } from "./parser.js";
@@ -47,12 +47,15 @@ interface OptionOptions {
47
47
  */
48
48
  readonly description?: Message;
49
49
  /**
50
- * When `true`, hides the option from help text, shell completion
51
- * suggestions, and "Did you mean?" error suggestions. The option
52
- * remains fully functional for parsing.
50
+ * Controls option visibility:
51
+ *
52
+ * - `true`: hide from usage, docs, and suggestions
53
+ * - `"usage"`: hide from usage only
54
+ * - `"doc"`: hide from docs only
55
+ *
53
56
  * @since 0.9.0
54
57
  */
55
- readonly hidden?: boolean;
58
+ readonly hidden?: HiddenVisibility;
56
59
  /**
57
60
  * Error message customization options.
58
61
  * @since 0.5.0
@@ -155,12 +158,15 @@ interface FlagOptions {
155
158
  */
156
159
  readonly description?: Message;
157
160
  /**
158
- * When `true`, hides the flag from help text, shell completion
159
- * suggestions, and "Did you mean?" error suggestions. The flag
160
- * remains fully functional for parsing.
161
+ * Controls flag visibility:
162
+ *
163
+ * - `true`: hide from usage, docs, and suggestions
164
+ * - `"usage"`: hide from usage only
165
+ * - `"doc"`: hide from docs only
166
+ *
161
167
  * @since 0.9.0
162
168
  */
163
- readonly hidden?: boolean;
169
+ readonly hidden?: HiddenVisibility;
164
170
  /**
165
171
  * Error message customization options.
166
172
  * @since 0.5.0
@@ -241,12 +247,15 @@ interface ArgumentOptions {
241
247
  */
242
248
  readonly description?: Message;
243
249
  /**
244
- * When `true`, hides the argument from help text, shell completion
245
- * suggestions, and error suggestions. The argument remains fully
246
- * functional for parsing.
250
+ * Controls argument visibility:
251
+ *
252
+ * - `true`: hide from usage, docs, and suggestions
253
+ * - `"usage"`: hide from usage only
254
+ * - `"doc"`: hide from docs only
255
+ *
247
256
  * @since 0.9.0
248
257
  */
249
- readonly hidden?: boolean;
258
+ readonly hidden?: HiddenVisibility;
250
259
  /**
251
260
  * Error message customization options.
252
261
  * @since 0.5.0
@@ -312,12 +321,15 @@ interface CommandOptions {
312
321
  */
313
322
  readonly footer?: Message;
314
323
  /**
315
- * When `true`, hides the command from help text, shell completion
316
- * suggestions, and "Did you mean?" error suggestions. The command
317
- * remains fully functional for parsing.
324
+ * Controls command visibility:
325
+ *
326
+ * - `true`: hide from usage, docs, and suggestions
327
+ * - `"usage"`: hide from usage only
328
+ * - `"doc"`: hide from docs only
329
+ *
318
330
  * @since 0.9.0
319
331
  */
320
- readonly hidden?: boolean;
332
+ readonly hidden?: HiddenVisibility;
321
333
  /**
322
334
  * Error messages customization.
323
335
  * @since 0.5.0
@@ -396,11 +408,15 @@ interface PassThroughOptions {
396
408
  */
397
409
  readonly description?: Message;
398
410
  /**
399
- * When `true`, hides the pass-through from help text and shell
400
- * completion suggestions. The parser remains fully functional.
411
+ * Controls pass-through visibility:
412
+ *
413
+ * - `true`: hide from usage, docs, and suggestions
414
+ * - `"usage"`: hide from usage only
415
+ * - `"doc"`: hide from docs only
416
+ *
401
417
  * @since 0.9.0
402
418
  */
403
- readonly hidden?: boolean;
419
+ readonly hidden?: HiddenVisibility;
404
420
  }
405
421
  /**
406
422
  * Creates a parser that collects unrecognized options and passes them through.
@@ -1,6 +1,6 @@
1
1
  import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
2
2
  import { createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependencyId, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, suggestWithDependency } from "./dependency.js";
3
- import { extractOptionNames } from "./usage.js";
3
+ import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
4
4
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, findSimilar } from "./suggestion.js";
5
5
  import { extractLeadingCommandNames } from "./usage-internals.js";
6
6
  import { isValueParser } from "./valueparser.js";
@@ -313,13 +313,13 @@ function option(...args) {
313
313
  terms: [{
314
314
  type: "option",
315
315
  names: optionNames$1,
316
- ...options.hidden && { hidden: true }
316
+ ...options.hidden != null && { hidden: options.hidden }
317
317
  }]
318
318
  } : {
319
319
  type: "option",
320
320
  names: optionNames$1,
321
321
  metavar: valueParser.metavar,
322
- ...options.hidden && { hidden: true }
322
+ ...options.hidden != null && { hidden: options.hidden }
323
323
  }],
324
324
  initialState: valueParser == null ? {
325
325
  success: true,
@@ -505,11 +505,11 @@ function option(...args) {
505
505
  };
506
506
  },
507
507
  suggest(context, prefix) {
508
- if (isAsync) return suggestOptionAsync(optionNames$1, valueParser, options.hidden ?? false, context, prefix);
509
- return suggestOptionSync(optionNames$1, valueParser, options.hidden ?? false, context, prefix);
508
+ if (isAsync) return suggestOptionAsync(optionNames$1, valueParser, isSuggestionHidden(options.hidden), context, prefix);
509
+ return suggestOptionSync(optionNames$1, valueParser, isSuggestionHidden(options.hidden), context, prefix);
510
510
  },
511
511
  getDocFragments(_state, defaultValue) {
512
- if (options.hidden) return {
512
+ if (isDocHidden(options.hidden)) return {
513
513
  fragments: [],
514
514
  description: options.description
515
515
  };
@@ -583,7 +583,7 @@ function flag(...args) {
583
583
  usage: [{
584
584
  type: "option",
585
585
  names: optionNames$1,
586
- ...options.hidden && { hidden: true }
586
+ ...options.hidden != null && { hidden: options.hidden }
587
587
  }],
588
588
  initialState: void 0,
589
589
  parse(context) {
@@ -690,7 +690,7 @@ function flag(...args) {
690
690
  };
691
691
  },
692
692
  suggest(_context, prefix) {
693
- if (options.hidden) return [];
693
+ if (isSuggestionHidden(options.hidden)) return [];
694
694
  const suggestions = [];
695
695
  if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/")) {
696
696
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
@@ -704,7 +704,7 @@ function flag(...args) {
704
704
  return suggestions;
705
705
  },
706
706
  getDocFragments(_state, _defaultValue) {
707
- if (options.hidden) return {
707
+ if (isDocHidden(options.hidden)) return {
708
708
  fragments: [],
709
709
  description: options.description
710
710
  };
@@ -745,7 +745,7 @@ function argument(valueParser, options = {}) {
745
745
  const term = {
746
746
  type: "argument",
747
747
  metavar: valueParser.metavar,
748
- ...options.hidden && { hidden: true }
748
+ ...options.hidden != null && { hidden: options.hidden }
749
749
  };
750
750
  const result = {
751
751
  $mode: valueParser.$mode,
@@ -833,11 +833,11 @@ function argument(valueParser, options = {}) {
833
833
  };
834
834
  },
835
835
  suggest(context, prefix) {
836
- if (isAsync) return suggestArgumentAsync(valueParser, options.hidden ?? false, prefix, context.dependencyRegistry);
837
- return suggestArgumentSync(valueParser, options.hidden ?? false, prefix, context.dependencyRegistry);
836
+ if (isAsync) return suggestArgumentAsync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
837
+ return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
838
838
  },
839
839
  getDocFragments(_state, defaultValue) {
840
- if (options.hidden) return {
840
+ if (isDocHidden(options.hidden)) return {
841
841
  fragments: [],
842
842
  description: options.description
843
843
  };
@@ -861,7 +861,7 @@ function argument(valueParser, options = {}) {
861
861
  return result;
862
862
  }
863
863
  function* suggestCommandSync(context, prefix, name, parser, options) {
864
- if (options.hidden) return;
864
+ if (isSuggestionHidden(options.hidden)) return;
865
865
  if (context.state === void 0) {
866
866
  if (name.startsWith(prefix)) yield {
867
867
  kind: "literal",
@@ -878,7 +878,7 @@ function* suggestCommandSync(context, prefix, name, parser, options) {
878
878
  }, prefix);
879
879
  }
880
880
  async function* suggestCommandAsync(context, prefix, name, parser, options) {
881
- if (options.hidden) return;
881
+ if (isSuggestionHidden(options.hidden)) return;
882
882
  if (context.state === void 0) {
883
883
  if (name.startsWith(prefix)) yield {
884
884
  kind: "literal",
@@ -923,7 +923,7 @@ function command(name, parser, options = {}) {
923
923
  usage: [{
924
924
  type: "command",
925
925
  name,
926
- ...options.hidden && { hidden: true }
926
+ ...options.hidden != null && { hidden: options.hidden }
927
927
  }, ...parser.usage],
928
928
  initialState: void 0,
929
929
  parse(context) {
@@ -1023,7 +1023,7 @@ function command(name, parser, options = {}) {
1023
1023
  },
1024
1024
  getDocFragments(state, defaultValue) {
1025
1025
  if (state.kind === "unavailable" || typeof state.state === "undefined") {
1026
- if (options.hidden) return {
1026
+ if (isDocHidden(options.hidden)) return {
1027
1027
  fragments: [],
1028
1028
  description: options.description
1029
1029
  };
@@ -1117,7 +1117,7 @@ function passThrough(options = {}) {
1117
1117
  priority: -10,
1118
1118
  usage: [{
1119
1119
  type: "passthrough",
1120
- ...options.hidden && { hidden: true }
1120
+ ...options.hidden != null && { hidden: options.hidden }
1121
1121
  }],
1122
1122
  initialState: [],
1123
1123
  parse(context) {
@@ -1215,7 +1215,7 @@ function passThrough(options = {}) {
1215
1215
  return [];
1216
1216
  },
1217
1217
  getDocFragments(_state, _defaultValue) {
1218
- if (options.hidden) return {
1218
+ if (isDocHidden(options.hidden)) return {
1219
1219
  fragments: [],
1220
1220
  description: options.description
1221
1221
  };
package/dist/usage.cjs CHANGED
@@ -1,6 +1,34 @@
1
1
 
2
2
  //#region src/usage.ts
3
3
  /**
4
+ * Returns whether the term should be hidden from usage output.
5
+ */
6
+ function isUsageHidden(hidden) {
7
+ return hidden === true || hidden === "usage";
8
+ }
9
+ /**
10
+ * Returns whether the term should be hidden from documentation output.
11
+ */
12
+ function isDocHidden(hidden) {
13
+ return hidden === true || hidden === "doc";
14
+ }
15
+ /**
16
+ * Returns whether the term should be hidden from suggestion/error candidates.
17
+ */
18
+ function isSuggestionHidden(hidden) {
19
+ return hidden === true;
20
+ }
21
+ /**
22
+ * Merges two hidden visibility settings by taking the union of restrictions.
23
+ */
24
+ function mergeHidden(a, b) {
25
+ if (a == null) return b;
26
+ if (b == null) return a;
27
+ if (a === true || b === true) return true;
28
+ if (a !== b) return true;
29
+ return a;
30
+ }
31
+ /**
4
32
  * Extracts all option names from a usage description.
5
33
  *
6
34
  * This function recursively traverses a {@link Usage} tree and collects all
@@ -25,7 +53,7 @@ function extractOptionNames(usage) {
25
53
  function traverseUsage(terms) {
26
54
  if (!terms || !Array.isArray(terms)) return;
27
55
  for (const term of terms) if (term.type === "option") {
28
- if (term.hidden) continue;
56
+ if (isSuggestionHidden(term.hidden)) continue;
29
57
  for (const name of term.names) names.add(name);
30
58
  } else if (term.type === "optional" || term.type === "multiple") traverseUsage(term.terms);
31
59
  else if (term.type === "exclusive") for (const exclusiveUsage of term.terms) traverseUsage(exclusiveUsage);
@@ -58,7 +86,7 @@ function extractCommandNames(usage) {
58
86
  function traverseUsage(terms) {
59
87
  if (!terms || !Array.isArray(terms)) return;
60
88
  for (const term of terms) if (term.type === "command") {
61
- if (term.hidden) continue;
89
+ if (isSuggestionHidden(term.hidden)) continue;
62
90
  names.add(term.name);
63
91
  } else if (term.type === "optional" || term.type === "multiple") traverseUsage(term.terms);
64
92
  else if (term.type === "exclusive") for (const exclusiveUsage of term.terms) traverseUsage(exclusiveUsage);
@@ -92,7 +120,7 @@ function extractArgumentMetavars(usage) {
92
120
  function traverseUsage(terms) {
93
121
  if (!terms || !Array.isArray(terms)) return;
94
122
  for (const term of terms) if (term.type === "argument") {
95
- if (term.hidden) continue;
123
+ if (isSuggestionHidden(term.hidden)) continue;
96
124
  metavars.add(term.metavar);
97
125
  } else if (term.type === "optional" || term.type === "multiple") traverseUsage(term.terms);
98
126
  else if (term.type === "exclusive") for (const exclusiveUsage of term.terms) traverseUsage(exclusiveUsage);
@@ -117,14 +145,14 @@ function extractArgumentMetavars(usage) {
117
145
  * @returns A formatted string representation of the usage description.
118
146
  */
119
147
  function formatUsage(programName, usage, options = {}) {
120
- usage = normalizeUsage(usage);
148
+ usage = normalizeUsage(filterUsageForDisplay(usage));
121
149
  if (options.expandCommands) {
122
150
  const lastTerm = usage.at(-1);
123
151
  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
152
  const lines = [];
125
153
  for (let command of lastTerm.terms) {
126
154
  const firstTerm = command[0];
127
- if (firstTerm?.type === "command" && firstTerm.hidden) continue;
155
+ if (firstTerm?.type === "command" && isUsageHidden(firstTerm.hidden)) continue;
128
156
  if (usage.length > 1) command = [...usage.slice(0, -1), ...command];
129
157
  lines.push(formatUsage(programName, command, options));
130
158
  }
@@ -205,9 +233,47 @@ function normalizeUsageTerm(term) {
205
233
  };
206
234
  } else return term;
207
235
  }
236
+ function filterUsageForDisplay(usage) {
237
+ const terms = [];
238
+ for (const term of usage) {
239
+ if ((term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") && isUsageHidden(term.hidden)) continue;
240
+ if (term.type === "optional") {
241
+ const filtered = filterUsageForDisplay(term.terms);
242
+ if (filtered.length > 0) terms.push({
243
+ type: "optional",
244
+ terms: filtered
245
+ });
246
+ continue;
247
+ }
248
+ if (term.type === "multiple") {
249
+ const filtered = filterUsageForDisplay(term.terms);
250
+ if (filtered.length > 0) terms.push({
251
+ type: "multiple",
252
+ terms: filtered,
253
+ min: term.min
254
+ });
255
+ continue;
256
+ }
257
+ if (term.type === "exclusive") {
258
+ const filteredBranches = term.terms.map((branch) => {
259
+ const first = branch[0];
260
+ if (first?.type === "command" && isUsageHidden(first.hidden)) return [];
261
+ return filterUsageForDisplay(branch);
262
+ }).filter((branch) => branch.length > 0);
263
+ if (filteredBranches.length > 0) terms.push({
264
+ type: "exclusive",
265
+ terms: filteredBranches
266
+ });
267
+ continue;
268
+ }
269
+ terms.push(term);
270
+ }
271
+ return terms;
272
+ }
208
273
  function* formatUsageTerms(terms, options) {
209
274
  let i = 0;
210
275
  for (const t of terms) {
276
+ if ("hidden" in t && (t.type === "argument" || t.type === "option" || t.type === "command" || t.type === "passthrough") && isUsageHidden(t.hidden)) continue;
211
277
  if (i > 0) yield {
212
278
  text: " ",
213
279
  width: 1
@@ -226,9 +292,11 @@ function* formatUsageTerms(terms, options) {
226
292
  * @returns A formatted string representation of the usage term.
227
293
  */
228
294
  function formatUsageTerm(term, options = {}) {
295
+ const visibleTerms = filterUsageForDisplay([term]);
296
+ if (visibleTerms.length < 1) return "";
229
297
  let lineWidth = 0;
230
298
  let output = "";
231
- for (const { text, width } of formatUsageTermInternal(term, options)) {
299
+ for (const { text, width } of formatUsageTermInternal(visibleTerms[0], options)) {
232
300
  if (options.maxWidth != null && lineWidth + width > options.maxWidth) {
233
301
  output += "\n";
234
302
  lineWidth = 0;
@@ -356,4 +424,8 @@ exports.extractCommandNames = extractCommandNames;
356
424
  exports.extractOptionNames = extractOptionNames;
357
425
  exports.formatUsage = formatUsage;
358
426
  exports.formatUsageTerm = formatUsageTerm;
427
+ exports.isDocHidden = isDocHidden;
428
+ exports.isSuggestionHidden = isSuggestionHidden;
429
+ exports.isUsageHidden = isUsageHidden;
430
+ exports.mergeHidden = mergeHidden;
359
431
  exports.normalizeUsage = normalizeUsage;