@optique/core 1.0.0-dev.1323 → 1.0.0-dev.1326

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/doc.cjs CHANGED
@@ -3,6 +3,23 @@ const require_usage = require('./usage.cjs');
3
3
 
4
4
  //#region src/doc.ts
5
5
  /**
6
+ * Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
7
+ * {@link cloneUsageTerm}, and `description`, `default`, and `choices`
8
+ * messages are cloned via {@link cloneMessage}.
9
+ *
10
+ * @param entry The documentation entry to clone.
11
+ * @returns A structurally equal but referentially distinct copy.
12
+ * @since 1.0.0
13
+ */
14
+ function cloneDocEntry(entry) {
15
+ return {
16
+ term: require_usage.cloneUsageTerm(entry.term),
17
+ ...entry.description != null && { description: require_message.cloneMessage(entry.description) },
18
+ ...entry.default != null && { default: require_message.cloneMessage(entry.default) },
19
+ ...entry.choices != null && { choices: require_message.cloneMessage(entry.choices) }
20
+ };
21
+ }
22
+ /**
6
23
  * Classifies a {@link DocSection} by its content type for use in the
7
24
  * default smart sort.
8
25
  *
@@ -327,4 +344,5 @@ function lastLineVisibleLength(text$1) {
327
344
  }
328
345
 
329
346
  //#endregion
347
+ exports.cloneDocEntry = cloneDocEntry;
330
348
  exports.formatDocPage = formatDocPage;
package/dist/doc.d.cts CHANGED
@@ -103,6 +103,16 @@ interface DocFragments {
103
103
  */
104
104
  readonly footer?: Message;
105
105
  }
106
+ /**
107
+ * Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
108
+ * {@link cloneUsageTerm}, and `description`, `default`, and `choices`
109
+ * messages are cloned via {@link cloneMessage}.
110
+ *
111
+ * @param entry The documentation entry to clone.
112
+ * @returns A structurally equal but referentially distinct copy.
113
+ * @since 1.0.0
114
+ */
115
+ declare function cloneDocEntry(entry: DocEntry): DocEntry;
106
116
  /**
107
117
  * Configuration for customizing default value display formatting.
108
118
  *
@@ -291,4 +301,4 @@ interface DocPageFormatOptions {
291
301
  */
292
302
  declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
293
303
  //#endregion
294
- export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage };
304
+ export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, formatDocPage };
package/dist/doc.d.ts CHANGED
@@ -103,6 +103,16 @@ interface DocFragments {
103
103
  */
104
104
  readonly footer?: Message;
105
105
  }
106
+ /**
107
+ * Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
108
+ * {@link cloneUsageTerm}, and `description`, `default`, and `choices`
109
+ * messages are cloned via {@link cloneMessage}.
110
+ *
111
+ * @param entry The documentation entry to clone.
112
+ * @returns A structurally equal but referentially distinct copy.
113
+ * @since 1.0.0
114
+ */
115
+ declare function cloneDocEntry(entry: DocEntry): DocEntry;
106
116
  /**
107
117
  * Configuration for customizing default value display formatting.
108
118
  *
@@ -291,4 +301,4 @@ interface DocPageFormatOptions {
291
301
  */
292
302
  declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
293
303
  //#endregion
294
- export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage };
304
+ export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, formatDocPage };
package/dist/doc.js CHANGED
@@ -1,8 +1,25 @@
1
- import { formatMessage, text } from "./message.js";
2
- import { formatUsage, formatUsageTerm } from "./usage.js";
1
+ import { cloneMessage, formatMessage, text } from "./message.js";
2
+ import { cloneUsageTerm, formatUsage, formatUsageTerm } from "./usage.js";
3
3
 
4
4
  //#region src/doc.ts
5
5
  /**
6
+ * Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
7
+ * {@link cloneUsageTerm}, and `description`, `default`, and `choices`
8
+ * messages are cloned via {@link cloneMessage}.
9
+ *
10
+ * @param entry The documentation entry to clone.
11
+ * @returns A structurally equal but referentially distinct copy.
12
+ * @since 1.0.0
13
+ */
14
+ function cloneDocEntry(entry) {
15
+ return {
16
+ term: cloneUsageTerm(entry.term),
17
+ ...entry.description != null && { description: cloneMessage(entry.description) },
18
+ ...entry.default != null && { default: cloneMessage(entry.default) },
19
+ ...entry.choices != null && { choices: cloneMessage(entry.choices) }
20
+ };
21
+ }
22
+ /**
6
23
  * Classifies a {@link DocSection} by its content type for use in the
7
24
  * default smart sort.
8
25
  *
@@ -327,4 +344,4 @@ function lastLineVisibleLength(text$1) {
327
344
  }
328
345
 
329
346
  //#endregion
330
- export { formatDocPage };
347
+ export { cloneDocEntry, formatDocPage };
package/dist/index.cjs CHANGED
@@ -23,6 +23,9 @@ exports.checkBooleanOption = require_valueparser.checkBooleanOption;
23
23
  exports.checkEnumOption = require_valueparser.checkEnumOption;
24
24
  exports.choice = require_valueparser.choice;
25
25
  exports.cidr = require_valueparser.cidr;
26
+ exports.cloneDocEntry = require_doc.cloneDocEntry;
27
+ exports.cloneUsage = require_usage.cloneUsage;
28
+ exports.cloneUsageTerm = require_usage.cloneUsageTerm;
26
29
  exports.command = require_primitives.command;
27
30
  exports.commandLine = require_message.commandLine;
28
31
  exports.concat = require_constructs.concat;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.cjs";
2
2
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
4
- import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
5
- import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
4
+ import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
5
+ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, formatDocPage } from "./doc.cjs";
6
6
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.cjs";
7
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";
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
12
12
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
13
13
  import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
14
14
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.js";
2
2
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
4
- import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
5
- import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.js";
4
+ import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
5
+ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, formatDocPage } from "./doc.js";
6
6
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
7
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";
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
12
12
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
13
13
  import { ParserValuePlaceholder, SourceContext } from "./context.js";
14
14
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ import { annotationKey, getAnnotations } from "./annotations.js";
2
2
  import { commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
3
3
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
4
4
  import { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
5
- import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
5
+ import { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
6
6
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
7
- import { formatDocPage } from "./doc.js";
7
+ import { cloneDocEntry, formatDocPage } from "./doc.js";
8
8
  import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
9
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
10
10
  import { checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
@@ -12,4 +12,4 @@ import { argument, command, constant, fail, flag, option, passThrough } from "./
12
12
  import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
13
13
  import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
14
14
 
15
- export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/message.cjs CHANGED
@@ -1,6 +1,44 @@
1
1
 
2
2
  //#region src/message.ts
3
3
  /**
4
+ * Creates a deep clone of a {@link MessageTerm}. Most variants contain only
5
+ * primitive fields and are cloned via object spread. The `url` variant
6
+ * receives a new `URL` object (since `structuredClone` cannot handle `URL`
7
+ * on Node.js), and array-valued fields (`optionNames`, `values`) are
8
+ * shallow-copied.
9
+ *
10
+ * @param term The message term to clone.
11
+ * @returns A structurally equal but referentially distinct copy.
12
+ * @since 1.0.0
13
+ */
14
+ function cloneMessageTerm(term) {
15
+ switch (term.type) {
16
+ case "optionNames": return {
17
+ ...term,
18
+ optionNames: [...term.optionNames]
19
+ };
20
+ case "values": return {
21
+ ...term,
22
+ values: [...term.values]
23
+ };
24
+ case "url": return {
25
+ type: "url",
26
+ url: new URL(term.url.href)
27
+ };
28
+ default: return { ...term };
29
+ }
30
+ }
31
+ /**
32
+ * Creates a deep clone of a {@link Message} array and all of its terms.
33
+ *
34
+ * @param msg The message to clone.
35
+ * @returns A structurally equal but referentially distinct copy.
36
+ * @since 1.0.0
37
+ */
38
+ function cloneMessage(msg) {
39
+ return msg.map(cloneMessageTerm);
40
+ }
41
+ /**
4
42
  * Creates a structured message with template strings and values.
5
43
  *
6
44
  * This function allows creating messages where specific values can be
@@ -386,6 +424,8 @@ function formatMessage(msg, options = {}) {
386
424
  }
387
425
 
388
426
  //#endregion
427
+ exports.cloneMessage = cloneMessage;
428
+ exports.cloneMessageTerm = cloneMessageTerm;
389
429
  exports.commandLine = commandLine;
390
430
  exports.envVar = envVar;
391
431
  exports.formatMessage = formatMessage;
@@ -151,6 +151,26 @@ type MessageTerm =
151
151
  * displayed to the user with specific formatting.
152
152
  */
153
153
  type Message = readonly MessageTerm[];
154
+ /**
155
+ * Creates a deep clone of a {@link MessageTerm}. Most variants contain only
156
+ * primitive fields and are cloned via object spread. The `url` variant
157
+ * receives a new `URL` object (since `structuredClone` cannot handle `URL`
158
+ * on Node.js), and array-valued fields (`optionNames`, `values`) are
159
+ * shallow-copied.
160
+ *
161
+ * @param term The message term to clone.
162
+ * @returns A structurally equal but referentially distinct copy.
163
+ * @since 1.0.0
164
+ */
165
+ declare function cloneMessageTerm(term: MessageTerm): MessageTerm;
166
+ /**
167
+ * Creates a deep clone of a {@link Message} array and all of its terms.
168
+ *
169
+ * @param msg The message to clone.
170
+ * @returns A structurally equal but referentially distinct copy.
171
+ * @since 1.0.0
172
+ */
173
+ declare function cloneMessage(msg: Message): Message;
154
174
  /**
155
175
  * Creates a structured message with template strings and values.
156
176
  *
@@ -380,4 +400,4 @@ interface MessageFormatOptions {
380
400
  */
381
401
  declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
382
402
  //#endregion
383
- export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
403
+ export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, cloneMessage, cloneMessageTerm, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
package/dist/message.d.ts CHANGED
@@ -151,6 +151,26 @@ type MessageTerm =
151
151
  * displayed to the user with specific formatting.
152
152
  */
153
153
  type Message = readonly MessageTerm[];
154
+ /**
155
+ * Creates a deep clone of a {@link MessageTerm}. Most variants contain only
156
+ * primitive fields and are cloned via object spread. The `url` variant
157
+ * receives a new `URL` object (since `structuredClone` cannot handle `URL`
158
+ * on Node.js), and array-valued fields (`optionNames`, `values`) are
159
+ * shallow-copied.
160
+ *
161
+ * @param term The message term to clone.
162
+ * @returns A structurally equal but referentially distinct copy.
163
+ * @since 1.0.0
164
+ */
165
+ declare function cloneMessageTerm(term: MessageTerm): MessageTerm;
166
+ /**
167
+ * Creates a deep clone of a {@link Message} array and all of its terms.
168
+ *
169
+ * @param msg The message to clone.
170
+ * @returns A structurally equal but referentially distinct copy.
171
+ * @since 1.0.0
172
+ */
173
+ declare function cloneMessage(msg: Message): Message;
154
174
  /**
155
175
  * Creates a structured message with template strings and values.
156
176
  *
@@ -380,4 +400,4 @@ interface MessageFormatOptions {
380
400
  */
381
401
  declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
382
402
  //#endregion
383
- export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
403
+ export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, cloneMessage, cloneMessageTerm, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
package/dist/message.js CHANGED
@@ -1,5 +1,43 @@
1
1
  //#region src/message.ts
2
2
  /**
3
+ * Creates a deep clone of a {@link MessageTerm}. Most variants contain only
4
+ * primitive fields and are cloned via object spread. The `url` variant
5
+ * receives a new `URL` object (since `structuredClone` cannot handle `URL`
6
+ * on Node.js), and array-valued fields (`optionNames`, `values`) are
7
+ * shallow-copied.
8
+ *
9
+ * @param term The message term to clone.
10
+ * @returns A structurally equal but referentially distinct copy.
11
+ * @since 1.0.0
12
+ */
13
+ function cloneMessageTerm(term) {
14
+ switch (term.type) {
15
+ case "optionNames": return {
16
+ ...term,
17
+ optionNames: [...term.optionNames]
18
+ };
19
+ case "values": return {
20
+ ...term,
21
+ values: [...term.values]
22
+ };
23
+ case "url": return {
24
+ type: "url",
25
+ url: new URL(term.url.href)
26
+ };
27
+ default: return { ...term };
28
+ }
29
+ }
30
+ /**
31
+ * Creates a deep clone of a {@link Message} array and all of its terms.
32
+ *
33
+ * @param msg The message to clone.
34
+ * @returns A structurally equal but referentially distinct copy.
35
+ * @since 1.0.0
36
+ */
37
+ function cloneMessage(msg) {
38
+ return msg.map(cloneMessageTerm);
39
+ }
40
+ /**
3
41
  * Creates a structured message with template strings and values.
4
42
  *
5
43
  * This function allows creating messages where specific values can be
@@ -385,4 +423,4 @@ function formatMessage(msg, options = {}) {
385
423
  }
386
424
 
387
425
  //#endregion
388
- export { commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
426
+ export { cloneMessage, cloneMessageTerm, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
package/dist/parser.cjs CHANGED
@@ -3,6 +3,7 @@ const require_message = require('./message.cjs');
3
3
  const require_mode_dispatch = require('./mode-dispatch.cjs');
4
4
  const require_usage = require('./usage.cjs');
5
5
  const require_constructs = require('./constructs.cjs');
6
+ const require_doc = require('./doc.cjs');
6
7
  const require_modifiers = require('./modifiers.cjs');
7
8
  const require_primitives = require('./primitives.cjs');
8
9
 
@@ -388,13 +389,13 @@ function buildDocPage(parser, context, args) {
388
389
  untitledSection = { entries: [] };
389
390
  buildingSections.push(untitledSection);
390
391
  }
391
- untitledSection.entries.push(fragment);
392
+ untitledSection.entries.push(require_doc.cloneDocEntry(fragment));
392
393
  } else if (fragment.type === "section") if (fragment.title == null) {
393
394
  if (untitledSection == null) {
394
395
  untitledSection = { entries: [] };
395
396
  buildingSections.push(untitledSection);
396
397
  }
397
- untitledSection.entries.push(...fragment.entries);
398
+ untitledSection.entries.push(...fragment.entries.map(require_doc.cloneDocEntry));
398
399
  } else {
399
400
  let section = titledSectionMap.get(fragment.title);
400
401
  if (section == null) {
@@ -405,15 +406,15 @@ function buildDocPage(parser, context, args) {
405
406
  titledSectionMap.set(fragment.title, section);
406
407
  buildingSections.push(section);
407
408
  }
408
- section.entries.push(...fragment.entries);
409
+ section.entries.push(...fragment.entries.map(require_doc.cloneDocEntry));
409
410
  }
410
411
  const sections = buildingSections;
411
- const usage = [...require_usage.normalizeUsage(parser.usage)];
412
+ const usage = require_usage.cloneUsage(require_usage.normalizeUsage(parser.usage));
412
413
  const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
413
414
  if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
414
- const defaultUsageLine = usage.slice(usageIndex + 1);
415
+ const defaultUsageLine = require_usage.cloneUsage(usage.slice(usageIndex + 1));
415
416
  const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
416
- const normalizedCustomUsageLine = require_usage.normalizeUsage(customUsageLine);
417
+ const normalizedCustomUsageLine = require_usage.cloneUsage(require_usage.normalizeUsage(customUsageLine));
417
418
  usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
418
419
  };
419
420
  let i = 0;
@@ -434,17 +435,18 @@ function buildDocPage(parser, context, args) {
434
435
  if (effectiveArgs.length === 0 && usage.length > 0) {
435
436
  const first = usage[0];
436
437
  if (first.type === "command" && first.usageLine != null) {
437
- const defaultUsageLine = usage.slice(1);
438
+ const defaultUsageLine = require_usage.cloneUsage(usage.slice(1));
438
439
  const customUsageLine = typeof first.usageLine === "function" ? first.usageLine(defaultUsageLine) : first.usageLine;
439
- usage.splice(1, usage.length - 1, ...require_usage.normalizeUsage(customUsageLine));
440
+ const normalizedCustomUsageLine = require_usage.cloneUsage(require_usage.normalizeUsage(customUsageLine));
441
+ usage.splice(1, usage.length - 1, ...normalizedCustomUsageLine);
440
442
  }
441
443
  }
442
444
  return {
443
445
  usage,
444
446
  sections,
445
- ...brief != null && { brief },
446
- ...description != null && { description },
447
- ...footer != null && { footer }
447
+ ...brief != null && { brief: require_message.cloneMessage(brief) },
448
+ ...description != null && { description: require_message.cloneMessage(description) },
449
+ ...footer != null && { footer: require_message.cloneMessage(footer) }
448
450
  };
449
451
  }
450
452
 
package/dist/parser.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
2
- import { message } from "./message.js";
2
+ import { cloneMessage, message } from "./message.js";
3
3
  import { dispatchByMode } from "./mode-dispatch.js";
4
- import { normalizeUsage } from "./usage.js";
4
+ import { cloneUsage, normalizeUsage } from "./usage.js";
5
5
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
6
+ import { cloneDocEntry } from "./doc.js";
6
7
  import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
7
8
  import { argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
8
9
 
@@ -388,13 +389,13 @@ function buildDocPage(parser, context, args) {
388
389
  untitledSection = { entries: [] };
389
390
  buildingSections.push(untitledSection);
390
391
  }
391
- untitledSection.entries.push(fragment);
392
+ untitledSection.entries.push(cloneDocEntry(fragment));
392
393
  } else if (fragment.type === "section") if (fragment.title == null) {
393
394
  if (untitledSection == null) {
394
395
  untitledSection = { entries: [] };
395
396
  buildingSections.push(untitledSection);
396
397
  }
397
- untitledSection.entries.push(...fragment.entries);
398
+ untitledSection.entries.push(...fragment.entries.map(cloneDocEntry));
398
399
  } else {
399
400
  let section = titledSectionMap.get(fragment.title);
400
401
  if (section == null) {
@@ -405,15 +406,15 @@ function buildDocPage(parser, context, args) {
405
406
  titledSectionMap.set(fragment.title, section);
406
407
  buildingSections.push(section);
407
408
  }
408
- section.entries.push(...fragment.entries);
409
+ section.entries.push(...fragment.entries.map(cloneDocEntry));
409
410
  }
410
411
  const sections = buildingSections;
411
- const usage = [...normalizeUsage(parser.usage)];
412
+ const usage = cloneUsage(normalizeUsage(parser.usage));
412
413
  const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
413
414
  if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
414
- const defaultUsageLine = usage.slice(usageIndex + 1);
415
+ const defaultUsageLine = cloneUsage(usage.slice(usageIndex + 1));
415
416
  const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
416
- const normalizedCustomUsageLine = normalizeUsage(customUsageLine);
417
+ const normalizedCustomUsageLine = cloneUsage(normalizeUsage(customUsageLine));
417
418
  usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
418
419
  };
419
420
  let i = 0;
@@ -434,17 +435,18 @@ function buildDocPage(parser, context, args) {
434
435
  if (effectiveArgs.length === 0 && usage.length > 0) {
435
436
  const first = usage[0];
436
437
  if (first.type === "command" && first.usageLine != null) {
437
- const defaultUsageLine = usage.slice(1);
438
+ const defaultUsageLine = cloneUsage(usage.slice(1));
438
439
  const customUsageLine = typeof first.usageLine === "function" ? first.usageLine(defaultUsageLine) : first.usageLine;
439
- usage.splice(1, usage.length - 1, ...normalizeUsage(customUsageLine));
440
+ const normalizedCustomUsageLine = cloneUsage(normalizeUsage(customUsageLine));
441
+ usage.splice(1, usage.length - 1, ...normalizedCustomUsageLine);
440
442
  }
441
443
  }
442
444
  return {
443
445
  usage,
444
446
  sections,
445
- ...brief != null && { brief },
446
- ...description != null && { description },
447
- ...footer != null && { footer }
447
+ ...brief != null && { brief: cloneMessage(brief) },
448
+ ...description != null && { description: cloneMessage(description) },
449
+ ...footer != null && { footer: cloneMessage(footer) }
448
450
  };
449
451
  }
450
452
 
package/dist/usage.cjs CHANGED
@@ -237,6 +237,59 @@ function normalizeUsageTerm(term) {
237
237
  };
238
238
  } else return term;
239
239
  }
240
+ /**
241
+ * Creates a deep clone of a single {@link UsageTerm}. Recursive term
242
+ * variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
243
+ * For `command` terms, a function-valued `usageLine` is preserved by
244
+ * reference (functions are stateless callbacks), while an array-valued
245
+ * `usageLine` is deep-cloned.
246
+ *
247
+ * @param term The usage term to clone.
248
+ * @returns A structurally equal but referentially distinct copy.
249
+ * @since 1.0.0
250
+ */
251
+ function cloneUsageTerm(term) {
252
+ switch (term.type) {
253
+ case "argument": return { ...term };
254
+ case "option": return {
255
+ ...term,
256
+ names: [...term.names]
257
+ };
258
+ case "command": {
259
+ if (term.usageLine == null || typeof term.usageLine === "function") return { ...term };
260
+ return {
261
+ ...term,
262
+ usageLine: term.usageLine.map(cloneUsageTerm)
263
+ };
264
+ }
265
+ case "optional": return {
266
+ type: "optional",
267
+ terms: term.terms.map(cloneUsageTerm)
268
+ };
269
+ case "multiple": return {
270
+ type: "multiple",
271
+ terms: term.terms.map(cloneUsageTerm),
272
+ min: term.min
273
+ };
274
+ case "exclusive": return {
275
+ type: "exclusive",
276
+ terms: term.terms.map((u) => u.map(cloneUsageTerm))
277
+ };
278
+ case "literal":
279
+ case "passthrough":
280
+ case "ellipsis": return { ...term };
281
+ }
282
+ }
283
+ /**
284
+ * Creates a deep clone of a {@link Usage} array and all of its terms.
285
+ *
286
+ * @param usage The usage array to clone.
287
+ * @returns A mutable array of deeply cloned usage terms.
288
+ * @since 1.0.0
289
+ */
290
+ function cloneUsage(usage) {
291
+ return usage.map(cloneUsageTerm);
292
+ }
240
293
  function filterUsageForDisplay(usage, isHidden = isUsageHidden) {
241
294
  const terms = [];
242
295
  for (const term of usage) {
@@ -433,6 +486,8 @@ function* formatUsageTermInternal(term, options) {
433
486
  }
434
487
 
435
488
  //#endregion
489
+ exports.cloneUsage = cloneUsage;
490
+ exports.cloneUsageTerm = cloneUsageTerm;
436
491
  exports.extractArgumentMetavars = extractArgumentMetavars;
437
492
  exports.extractCommandNames = extractCommandNames;
438
493
  exports.extractOptionNames = extractOptionNames;
package/dist/usage.d.cts CHANGED
@@ -347,6 +347,26 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
347
347
  * and terms sorted for optimal readability.
348
348
  */
349
349
  declare function normalizeUsage(usage: Usage): Usage;
350
+ /**
351
+ * Creates a deep clone of a single {@link UsageTerm}. Recursive term
352
+ * variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
353
+ * For `command` terms, a function-valued `usageLine` is preserved by
354
+ * reference (functions are stateless callbacks), while an array-valued
355
+ * `usageLine` is deep-cloned.
356
+ *
357
+ * @param term The usage term to clone.
358
+ * @returns A structurally equal but referentially distinct copy.
359
+ * @since 1.0.0
360
+ */
361
+ declare function cloneUsageTerm(term: UsageTerm): UsageTerm;
362
+ /**
363
+ * Creates a deep clone of a {@link Usage} array and all of its terms.
364
+ *
365
+ * @param usage The usage array to clone.
366
+ * @returns A mutable array of deeply cloned usage terms.
367
+ * @since 1.0.0
368
+ */
369
+ declare function cloneUsage(usage: Usage): UsageTerm[];
350
370
  /**
351
371
  * Options for formatting a single {@link UsageTerm}.
352
372
  */
@@ -378,4 +398,4 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
378
398
  */
379
399
  declare function formatUsageTerm(term: UsageTerm, options?: UsageTermFormatOptions): string;
380
400
  //#endregion
381
- export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
401
+ export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
package/dist/usage.d.ts CHANGED
@@ -347,6 +347,26 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
347
347
  * and terms sorted for optimal readability.
348
348
  */
349
349
  declare function normalizeUsage(usage: Usage): Usage;
350
+ /**
351
+ * Creates a deep clone of a single {@link UsageTerm}. Recursive term
352
+ * variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
353
+ * For `command` terms, a function-valued `usageLine` is preserved by
354
+ * reference (functions are stateless callbacks), while an array-valued
355
+ * `usageLine` is deep-cloned.
356
+ *
357
+ * @param term The usage term to clone.
358
+ * @returns A structurally equal but referentially distinct copy.
359
+ * @since 1.0.0
360
+ */
361
+ declare function cloneUsageTerm(term: UsageTerm): UsageTerm;
362
+ /**
363
+ * Creates a deep clone of a {@link Usage} array and all of its terms.
364
+ *
365
+ * @param usage The usage array to clone.
366
+ * @returns A mutable array of deeply cloned usage terms.
367
+ * @since 1.0.0
368
+ */
369
+ declare function cloneUsage(usage: Usage): UsageTerm[];
350
370
  /**
351
371
  * Options for formatting a single {@link UsageTerm}.
352
372
  */
@@ -378,4 +398,4 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
378
398
  */
379
399
  declare function formatUsageTerm(term: UsageTerm, options?: UsageTermFormatOptions): string;
380
400
  //#endregion
381
- export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
401
+ export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
package/dist/usage.js CHANGED
@@ -236,6 +236,59 @@ function normalizeUsageTerm(term) {
236
236
  };
237
237
  } else return term;
238
238
  }
239
+ /**
240
+ * Creates a deep clone of a single {@link UsageTerm}. Recursive term
241
+ * variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
242
+ * For `command` terms, a function-valued `usageLine` is preserved by
243
+ * reference (functions are stateless callbacks), while an array-valued
244
+ * `usageLine` is deep-cloned.
245
+ *
246
+ * @param term The usage term to clone.
247
+ * @returns A structurally equal but referentially distinct copy.
248
+ * @since 1.0.0
249
+ */
250
+ function cloneUsageTerm(term) {
251
+ switch (term.type) {
252
+ case "argument": return { ...term };
253
+ case "option": return {
254
+ ...term,
255
+ names: [...term.names]
256
+ };
257
+ case "command": {
258
+ if (term.usageLine == null || typeof term.usageLine === "function") return { ...term };
259
+ return {
260
+ ...term,
261
+ usageLine: term.usageLine.map(cloneUsageTerm)
262
+ };
263
+ }
264
+ case "optional": return {
265
+ type: "optional",
266
+ terms: term.terms.map(cloneUsageTerm)
267
+ };
268
+ case "multiple": return {
269
+ type: "multiple",
270
+ terms: term.terms.map(cloneUsageTerm),
271
+ min: term.min
272
+ };
273
+ case "exclusive": return {
274
+ type: "exclusive",
275
+ terms: term.terms.map((u) => u.map(cloneUsageTerm))
276
+ };
277
+ case "literal":
278
+ case "passthrough":
279
+ case "ellipsis": return { ...term };
280
+ }
281
+ }
282
+ /**
283
+ * Creates a deep clone of a {@link Usage} array and all of its terms.
284
+ *
285
+ * @param usage The usage array to clone.
286
+ * @returns A mutable array of deeply cloned usage terms.
287
+ * @since 1.0.0
288
+ */
289
+ function cloneUsage(usage) {
290
+ return usage.map(cloneUsageTerm);
291
+ }
239
292
  function filterUsageForDisplay(usage, isHidden = isUsageHidden) {
240
293
  const terms = [];
241
294
  for (const term of usage) {
@@ -432,4 +485,4 @@ function* formatUsageTermInternal(term, options) {
432
485
  }
433
486
 
434
487
  //#endregion
435
- export { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
488
+ export { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1323+0653ad71",
3
+ "version": "1.0.0-dev.1326+40fd572e",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",