@optique/core 1.2.0-dev.2179 → 1.2.0-dev.2187

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.
@@ -2,6 +2,7 @@ import { Message } from "./message.cjs";
2
2
  import { HiddenVisibility, OptionName, Usage } from "./usage.cjs";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.cjs";
4
4
  import { Mode, Parser } from "./internal/parser.cjs";
5
+ import { FluentParser } from "./modifiers.cjs";
5
6
 
6
7
  //#region src/primitives.d.ts
7
8
  /** @internal */
@@ -11,7 +12,7 @@ type OptionState<T> = ValueParserResult<T> | undefined;
11
12
  * produces a constant value of the type {@link T}.
12
13
  * @template T The type of the constant value produced by the parser.
13
14
  */
14
- declare function constant<const T>(value: T): Parser<"sync", T, T>;
15
+ declare function constant<const T>(value: T): FluentParser<"sync", T, T>;
15
16
  /**
16
17
  * Creates a parser that always fails without consuming any input.
17
18
  *
@@ -31,7 +32,7 @@ declare function constant<const T>(value: T): Parser<"sync", T, T>;
31
32
  * complete time.
32
33
  * @since 1.0.0
33
34
  */
34
- declare function fail<T>(): Parser<"sync", T, undefined>;
35
+ declare function fail<T>(): FluentParser<"sync", T, undefined>;
35
36
  /**
36
37
  * Options for the {@link option} parser.
37
38
  */
@@ -113,7 +114,7 @@ interface OptionErrorOptions {
113
114
  * @returns A {@link Parser} that can parse the specified options and their
114
115
  * values.
115
116
  */
116
- declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>]): Parser<M, T, ValueParserResult<T> | undefined>;
117
+ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>]): FluentParser<M, T, ValueParserResult<T> | undefined>;
117
118
  /**
118
119
  * Creates a parser for various styles of command-line options that take an
119
120
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
@@ -127,7 +128,7 @@ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...rea
127
128
  * @returns A {@link Parser} that can parse the specified options and their
128
129
  * values.
129
130
  */
130
- declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>, OptionOptions]): Parser<M, T, ValueParserResult<T> | undefined>;
131
+ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>, OptionOptions]): FluentParser<M, T, ValueParserResult<T> | undefined>;
131
132
  /**
132
133
  * Creates a parser for various styles of command-line options that do not
133
134
  * take an argument value, such as `--option`, `-o`, or `/option`.
@@ -135,7 +136,7 @@ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...rea
135
136
  * @return A {@link Parser} that can parse the specified options as Boolean
136
137
  * flags, producing `true` if the option is present.
137
138
  */
138
- declare function option(...optionNames: readonly [OptionName, ...readonly OptionName[]]): Parser<"sync", boolean, ValueParserResult<boolean> | undefined>;
139
+ declare function option(...optionNames: readonly [OptionName, ...readonly OptionName[]]): FluentParser<"sync", boolean, ValueParserResult<boolean> | undefined>;
139
140
  /**
140
141
  * Creates a parser for various styles of command-line options that take an
141
142
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
@@ -146,7 +147,7 @@ declare function option(...optionNames: readonly [OptionName, ...readonly Option
146
147
  * @returns A {@link Parser} that can parse the specified options and their
147
148
  * values.
148
149
  */
149
- declare function option(...args: readonly [OptionName, ...readonly OptionName[], OptionOptions]): Parser<"sync", boolean, ValueParserResult<boolean> | undefined>;
150
+ declare function option(...args: readonly [OptionName, ...readonly OptionName[], OptionOptions]): FluentParser<"sync", boolean, ValueParserResult<boolean> | undefined>;
150
151
  /**
151
152
  * Options for the {@link flag} parser.
152
153
  */
@@ -236,7 +237,7 @@ interface FlagErrorOptions {
236
237
  * });
237
238
  * ```
238
239
  */
239
- declare function flag(...args: readonly [OptionName, ...readonly OptionName[], FlagOptions] | readonly [OptionName, ...readonly OptionName[]]): Parser<"sync", true, ValueParserResult<true> | undefined>;
240
+ declare function flag(...args: readonly [OptionName, ...readonly OptionName[], FlagOptions] | readonly [OptionName, ...readonly OptionName[]]): FluentParser<"sync", true, ValueParserResult<true> | undefined>;
240
241
  /**
241
242
  * A non-empty list of option names, or a single option name.
242
243
  * @since 1.1.0
@@ -340,7 +341,7 @@ interface NegatableFlagState {
340
341
  * side, or shared by the positive and negative sides.
341
342
  * @since 1.1.0
342
343
  */
343
- declare function negatableFlag(names: NegatableFlagNames, options?: NegatableFlagOptions): Parser<"sync", boolean, NegatableFlagState | undefined>;
344
+ declare function negatableFlag(names: NegatableFlagNames, options?: NegatableFlagOptions): FluentParser<"sync", boolean, NegatableFlagState | undefined>;
344
345
  /**
345
346
  * Options for the {@link argument} parser.
346
347
  */
@@ -399,7 +400,7 @@ interface ArgumentErrorOptions {
399
400
  * @returns A {@link Parser} that expects a single argument value and produces
400
401
  * the parsed value of type {@link T}.
401
402
  */
402
- declare function argument<M extends Mode, T>(valueParser: ValueParser<M, T>, options?: ArgumentOptions): Parser<M, T, ValueParserResult<T> | undefined>;
403
+ declare function argument<M extends Mode, T>(valueParser: ValueParser<M, T>, options?: ArgumentOptions): FluentParser<M, T, ValueParserResult<T> | undefined>;
403
404
  /**
404
405
  * Options for the {@link command} parser.
405
406
  * @since 0.5.0
@@ -507,7 +508,7 @@ type CommandState<TState> = undefined | ["matched", string] | ["parsing", TState
507
508
  * @throws {TypeError} If `name` is empty, whitespace-only, contains
508
509
  * embedded whitespace, or contains control characters.
509
510
  */
510
- declare function command<M extends Mode, T, TState>(name: string, parser: Parser<M, T, TState>, options?: CommandOptions): Parser<M, T, CommandState<TState>>;
511
+ declare function command<M extends Mode, T, TState>(name: string, parser: Parser<M, T, TState>, options?: CommandOptions): FluentParser<M, T, CommandState<TState>>;
511
512
  /**
512
513
  * Format options for how {@link passThrough} captures options.
513
514
  * @since 0.8.0
@@ -595,6 +596,6 @@ interface PassThroughOptions {
595
596
  *
596
597
  * @since 0.8.0
597
598
  */
598
- declare function passThrough(options?: PassThroughOptions): Parser<"sync", readonly string[], readonly string[]>;
599
+ declare function passThrough(options?: PassThroughOptions): FluentParser<"sync", readonly string[], readonly string[]>;
599
600
  //#endregion
600
601
  export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough };
@@ -2,6 +2,7 @@ import { Message } from "./message.js";
2
2
  import { HiddenVisibility, OptionName, Usage } from "./usage.js";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.js";
4
4
  import { Mode, Parser } from "./internal/parser.js";
5
+ import { FluentParser } from "./modifiers.js";
5
6
 
6
7
  //#region src/primitives.d.ts
7
8
  /** @internal */
@@ -11,7 +12,7 @@ type OptionState<T> = ValueParserResult<T> | undefined;
11
12
  * produces a constant value of the type {@link T}.
12
13
  * @template T The type of the constant value produced by the parser.
13
14
  */
14
- declare function constant<const T>(value: T): Parser<"sync", T, T>;
15
+ declare function constant<const T>(value: T): FluentParser<"sync", T, T>;
15
16
  /**
16
17
  * Creates a parser that always fails without consuming any input.
17
18
  *
@@ -31,7 +32,7 @@ declare function constant<const T>(value: T): Parser<"sync", T, T>;
31
32
  * complete time.
32
33
  * @since 1.0.0
33
34
  */
34
- declare function fail<T>(): Parser<"sync", T, undefined>;
35
+ declare function fail<T>(): FluentParser<"sync", T, undefined>;
35
36
  /**
36
37
  * Options for the {@link option} parser.
37
38
  */
@@ -113,7 +114,7 @@ interface OptionErrorOptions {
113
114
  * @returns A {@link Parser} that can parse the specified options and their
114
115
  * values.
115
116
  */
116
- declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>]): Parser<M, T, ValueParserResult<T> | undefined>;
117
+ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>]): FluentParser<M, T, ValueParserResult<T> | undefined>;
117
118
  /**
118
119
  * Creates a parser for various styles of command-line options that take an
119
120
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
@@ -127,7 +128,7 @@ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...rea
127
128
  * @returns A {@link Parser} that can parse the specified options and their
128
129
  * values.
129
130
  */
130
- declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>, OptionOptions]): Parser<M, T, ValueParserResult<T> | undefined>;
131
+ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...readonly OptionName[], ValueParser<M, T>, OptionOptions]): FluentParser<M, T, ValueParserResult<T> | undefined>;
131
132
  /**
132
133
  * Creates a parser for various styles of command-line options that do not
133
134
  * take an argument value, such as `--option`, `-o`, or `/option`.
@@ -135,7 +136,7 @@ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...rea
135
136
  * @return A {@link Parser} that can parse the specified options as Boolean
136
137
  * flags, producing `true` if the option is present.
137
138
  */
138
- declare function option(...optionNames: readonly [OptionName, ...readonly OptionName[]]): Parser<"sync", boolean, ValueParserResult<boolean> | undefined>;
139
+ declare function option(...optionNames: readonly [OptionName, ...readonly OptionName[]]): FluentParser<"sync", boolean, ValueParserResult<boolean> | undefined>;
139
140
  /**
140
141
  * Creates a parser for various styles of command-line options that take an
141
142
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
@@ -146,7 +147,7 @@ declare function option(...optionNames: readonly [OptionName, ...readonly Option
146
147
  * @returns A {@link Parser} that can parse the specified options and their
147
148
  * values.
148
149
  */
149
- declare function option(...args: readonly [OptionName, ...readonly OptionName[], OptionOptions]): Parser<"sync", boolean, ValueParserResult<boolean> | undefined>;
150
+ declare function option(...args: readonly [OptionName, ...readonly OptionName[], OptionOptions]): FluentParser<"sync", boolean, ValueParserResult<boolean> | undefined>;
150
151
  /**
151
152
  * Options for the {@link flag} parser.
152
153
  */
@@ -236,7 +237,7 @@ interface FlagErrorOptions {
236
237
  * });
237
238
  * ```
238
239
  */
239
- declare function flag(...args: readonly [OptionName, ...readonly OptionName[], FlagOptions] | readonly [OptionName, ...readonly OptionName[]]): Parser<"sync", true, ValueParserResult<true> | undefined>;
240
+ declare function flag(...args: readonly [OptionName, ...readonly OptionName[], FlagOptions] | readonly [OptionName, ...readonly OptionName[]]): FluentParser<"sync", true, ValueParserResult<true> | undefined>;
240
241
  /**
241
242
  * A non-empty list of option names, or a single option name.
242
243
  * @since 1.1.0
@@ -340,7 +341,7 @@ interface NegatableFlagState {
340
341
  * side, or shared by the positive and negative sides.
341
342
  * @since 1.1.0
342
343
  */
343
- declare function negatableFlag(names: NegatableFlagNames, options?: NegatableFlagOptions): Parser<"sync", boolean, NegatableFlagState | undefined>;
344
+ declare function negatableFlag(names: NegatableFlagNames, options?: NegatableFlagOptions): FluentParser<"sync", boolean, NegatableFlagState | undefined>;
344
345
  /**
345
346
  * Options for the {@link argument} parser.
346
347
  */
@@ -399,7 +400,7 @@ interface ArgumentErrorOptions {
399
400
  * @returns A {@link Parser} that expects a single argument value and produces
400
401
  * the parsed value of type {@link T}.
401
402
  */
402
- declare function argument<M extends Mode, T>(valueParser: ValueParser<M, T>, options?: ArgumentOptions): Parser<M, T, ValueParserResult<T> | undefined>;
403
+ declare function argument<M extends Mode, T>(valueParser: ValueParser<M, T>, options?: ArgumentOptions): FluentParser<M, T, ValueParserResult<T> | undefined>;
403
404
  /**
404
405
  * Options for the {@link command} parser.
405
406
  * @since 0.5.0
@@ -507,7 +508,7 @@ type CommandState<TState> = undefined | ["matched", string] | ["parsing", TState
507
508
  * @throws {TypeError} If `name` is empty, whitespace-only, contains
508
509
  * embedded whitespace, or contains control characters.
509
510
  */
510
- declare function command<M extends Mode, T, TState>(name: string, parser: Parser<M, T, TState>, options?: CommandOptions): Parser<M, T, CommandState<TState>>;
511
+ declare function command<M extends Mode, T, TState>(name: string, parser: Parser<M, T, TState>, options?: CommandOptions): FluentParser<M, T, CommandState<TState>>;
511
512
  /**
512
513
  * Format options for how {@link passThrough} captures options.
513
514
  * @since 0.8.0
@@ -595,6 +596,6 @@ interface PassThroughOptions {
595
596
  *
596
597
  * @since 0.8.0
597
598
  */
598
- declare function passThrough(options?: PassThroughOptions): Parser<"sync", readonly string[], readonly string[]>;
599
+ declare function passThrough(options?: PassThroughOptions): FluentParser<"sync", readonly string[], readonly string[]>;
599
600
  //#endregion
600
601
  export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough };
@@ -9,9 +9,10 @@ import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedIni
9
9
  import { hiddenCommandAliasesKey } from "./internal/command-alias.js";
10
10
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
11
11
  import { completeOrExtractPhase2Seed, extractPhase2SeedKey } from "./phase2-seed.js";
12
+ import { extractDependencyMetadata } from "./dependency-metadata.js";
13
+ import { fluent } from "./modifiers.js";
12
14
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, expandCommandAliasSuggestions, findSimilar } from "./suggestion.js";
13
15
  import { extractLeadingCommandNames } from "./usage-internals.js";
14
- import { extractDependencyMetadata } from "./dependency-metadata.js";
15
16
  import { isValueParser } from "./valueparser.js";
16
17
 
17
18
  //#region src/primitives.ts
@@ -150,7 +151,7 @@ function constant(value) {
150
151
  enumerable: false,
151
152
  writable: false
152
153
  });
153
- return result;
154
+ return fluent(result);
154
155
  }
155
156
  /**
156
157
  * Creates a parser that always fails without consuming any input.
@@ -172,7 +173,7 @@ function constant(value) {
172
173
  * @since 1.0.0
173
174
  */
174
175
  function fail() {
175
- return {
176
+ return fluent({
176
177
  $valueType: [],
177
178
  $stateType: [],
178
179
  mode: "sync",
@@ -203,7 +204,7 @@ function fail() {
203
204
  getDocFragments(_state, _defaultValue) {
204
205
  return { fragments: [] };
205
206
  }
206
- };
207
+ });
207
208
  }
208
209
  /**
209
210
  * Internal helper to get suggestions from a value parser, using dependency values
@@ -741,7 +742,7 @@ function option(...args) {
741
742
  configurable: true,
742
743
  enumerable: false
743
744
  });
744
- return result;
745
+ return fluent(result);
745
746
  }
746
747
  /**
747
748
  * Creates a parser for command-line flags that must be explicitly provided.
@@ -944,7 +945,7 @@ function flag(...args) {
944
945
  enumerable: false,
945
946
  writable: false
946
947
  });
947
- return result;
948
+ return fluent(result);
948
949
  }
949
950
  function normalizeNegatableFlagNameList(names) {
950
951
  return typeof names === "string" ? [names] : names;
@@ -1162,7 +1163,7 @@ function negatableFlag(names, options = {}) {
1162
1163
  enumerable: false,
1163
1164
  writable: false
1164
1165
  });
1165
- return result;
1166
+ return fluent(result);
1166
1167
  }
1167
1168
  /**
1168
1169
  * Creates a parser that expects a single argument value.
@@ -1371,7 +1372,7 @@ function argument(valueParser, options = {}) {
1371
1372
  configurable: true,
1372
1373
  enumerable: false
1373
1374
  });
1374
- return result;
1375
+ return fluent(result);
1375
1376
  }
1376
1377
  function normalizeCommandState(state) {
1377
1378
  return normalizeInjectedAnnotationState(state);
@@ -1700,7 +1701,7 @@ function command(name, parser, options = {}) {
1700
1701
  configurable: true,
1701
1702
  enumerable: false
1702
1703
  });
1703
- return result;
1704
+ return fluent(result);
1704
1705
  }
1705
1706
  /**
1706
1707
  * Creates a parser that collects unrecognized options and passes them through.
@@ -1752,7 +1753,7 @@ function passThrough(options = {}) {
1752
1753
  const format = options.format ?? "equalsOnly";
1753
1754
  const optionPattern = /^-[a-z0-9-]|^--[a-z0-9-]+/i;
1754
1755
  const equalsOptionPattern = /^--[a-z0-9-]+=/i;
1755
- return {
1756
+ const result = {
1756
1757
  $valueType: [],
1757
1758
  $stateType: [],
1758
1759
  mode: "sync",
@@ -1884,6 +1885,7 @@ function passThrough(options = {}) {
1884
1885
  return `passThrough(${format})`;
1885
1886
  }
1886
1887
  };
1888
+ return fluent(result);
1887
1889
  }
1888
1890
 
1889
1891
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.2.0-dev.2179",
3
+ "version": "1.2.0-dev.2187",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -123,6 +123,14 @@
123
123
  "import": "./dist/facade.js",
124
124
  "require": "./dist/facade.cjs"
125
125
  },
126
+ "./fluent": {
127
+ "types": {
128
+ "import": "./dist/fluent.d.ts",
129
+ "require": "./dist/fluent.d.cts"
130
+ },
131
+ "import": "./dist/fluent.js",
132
+ "require": "./dist/fluent.cjs"
133
+ },
126
134
  "./message": {
127
135
  "types": {
128
136
  "import": "./dist/message.d.ts",
@@ -200,7 +208,7 @@
200
208
  "fast-check": "^4.7.0",
201
209
  "tsdown": "^0.13.0",
202
210
  "typescript": "^5.8.3",
203
- "@optique/env": "1.2.0-dev.2179+919d5ae8"
211
+ "@optique/env": "1.2.0-dev.2187+6112b083"
204
212
  },
205
213
  "scripts": {
206
214
  "build": "tsdown",