@optique/core 1.0.0-dev.558 → 1.0.0-dev.560
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/modifiers.cjs +11 -2
- package/dist/modifiers.js +11 -2
- package/dist/primitives.cjs +7 -4
- package/dist/primitives.js +7 -4
- package/package.json +1 -1
package/dist/modifiers.cjs
CHANGED
|
@@ -175,6 +175,16 @@ var WithDefaultError = class extends Error {
|
|
|
175
175
|
};
|
|
176
176
|
function withDefault(parser, defaultValue, options) {
|
|
177
177
|
const syncParser = parser;
|
|
178
|
+
const getDocDefaultValue = (upperDefaultValue) => {
|
|
179
|
+
if (upperDefaultValue != null) return upperDefaultValue;
|
|
180
|
+
if (options?.message) return void 0;
|
|
181
|
+
if (typeof defaultValue !== "function") return defaultValue;
|
|
182
|
+
try {
|
|
183
|
+
return defaultValue();
|
|
184
|
+
} catch {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
178
188
|
function* suggestSync(context, prefix) {
|
|
179
189
|
const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
|
|
180
190
|
yield* syncParser.suggest({
|
|
@@ -318,8 +328,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
318
328
|
kind: "available",
|
|
319
329
|
state: state.state[0]
|
|
320
330
|
};
|
|
321
|
-
const
|
|
322
|
-
const fragments = syncParser.getDocFragments(innerState, actualDefaultValue);
|
|
331
|
+
const fragments = syncParser.getDocFragments(innerState, getDocDefaultValue(upperDefaultValue));
|
|
323
332
|
if (options?.message) {
|
|
324
333
|
const modifiedFragments = fragments.fragments.map((fragment) => {
|
|
325
334
|
if (fragment.type === "entry") return {
|
package/dist/modifiers.js
CHANGED
|
@@ -175,6 +175,16 @@ var WithDefaultError = class extends Error {
|
|
|
175
175
|
};
|
|
176
176
|
function withDefault(parser, defaultValue, options) {
|
|
177
177
|
const syncParser = parser;
|
|
178
|
+
const getDocDefaultValue = (upperDefaultValue) => {
|
|
179
|
+
if (upperDefaultValue != null) return upperDefaultValue;
|
|
180
|
+
if (options?.message) return void 0;
|
|
181
|
+
if (typeof defaultValue !== "function") return defaultValue;
|
|
182
|
+
try {
|
|
183
|
+
return defaultValue();
|
|
184
|
+
} catch {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
178
188
|
function* suggestSync(context, prefix) {
|
|
179
189
|
const innerState = Array.isArray(context.state) ? context.state[0] : syncParser.initialState;
|
|
180
190
|
yield* syncParser.suggest({
|
|
@@ -318,8 +328,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
318
328
|
kind: "available",
|
|
319
329
|
state: state.state[0]
|
|
320
330
|
};
|
|
321
|
-
const
|
|
322
|
-
const fragments = syncParser.getDocFragments(innerState, actualDefaultValue);
|
|
331
|
+
const fragments = syncParser.getDocFragments(innerState, getDocDefaultValue(upperDefaultValue));
|
|
323
332
|
if (options?.message) {
|
|
324
333
|
const modifiedFragments = fragments.fragments.map((fragment) => {
|
|
325
334
|
if (fragment.type === "entry") return {
|
package/dist/primitives.cjs
CHANGED
|
@@ -8,6 +8,10 @@ const require_usage_internals = require('./usage-internals.cjs');
|
|
|
8
8
|
const require_valueparser = require('./valueparser.cjs');
|
|
9
9
|
|
|
10
10
|
//#region src/primitives.ts
|
|
11
|
+
function hasParsedOptionValue(state, valueParser) {
|
|
12
|
+
if (valueParser != null) return require_dependency.isDeferredParseState(state) || require_dependency.isDependencySourceState(state) || state != null && "success" in state && state.success;
|
|
13
|
+
return state != null && "success" in state && state.success && state.value === true;
|
|
14
|
+
}
|
|
11
15
|
/**
|
|
12
16
|
* Helper function to create the appropriate state for an option value.
|
|
13
17
|
* - If the value parser is a DerivedValueParser, wraps the result in a DeferredParseState
|
|
@@ -354,8 +358,7 @@ function option(...args) {
|
|
|
354
358
|
consumed: context.buffer.slice(0, 1)
|
|
355
359
|
};
|
|
356
360
|
if (optionNames$1.includes(context.buffer[0])) {
|
|
357
|
-
|
|
358
|
-
if (hasValue) return {
|
|
361
|
+
if (hasParsedOptionValue(context.state, valueParser)) return {
|
|
359
362
|
success: false,
|
|
360
363
|
consumed: 1,
|
|
361
364
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${require_message.optionName(context.buffer[0])} cannot be used multiple times.`
|
|
@@ -401,7 +404,7 @@ function option(...args) {
|
|
|
401
404
|
const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => name.startsWith("/") ? `${name}:` : `${name}=`);
|
|
402
405
|
for (const prefix of prefixes) {
|
|
403
406
|
if (!context.buffer[0].startsWith(prefix)) continue;
|
|
404
|
-
if (context.state
|
|
407
|
+
if (hasParsedOptionValue(context.state, valueParser)) {
|
|
405
408
|
const optionName$1 = prefix.slice(0, -1);
|
|
406
409
|
return {
|
|
407
410
|
success: false,
|
|
@@ -439,7 +442,7 @@ function option(...args) {
|
|
|
439
442
|
const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/));
|
|
440
443
|
for (const shortOption of shortOptions) {
|
|
441
444
|
if (!context.buffer[0].startsWith(shortOption)) continue;
|
|
442
|
-
if (context.state
|
|
445
|
+
if (hasParsedOptionValue(context.state, valueParser)) return {
|
|
443
446
|
success: false,
|
|
444
447
|
consumed: 1,
|
|
445
448
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(shortOption) : options.errors.duplicate : require_message.message`${require_message.optionName(shortOption)} cannot be used multiple times.`
|
package/dist/primitives.js
CHANGED
|
@@ -8,6 +8,10 @@ import { extractLeadingCommandNames } from "./usage-internals.js";
|
|
|
8
8
|
import { isValueParser } from "./valueparser.js";
|
|
9
9
|
|
|
10
10
|
//#region src/primitives.ts
|
|
11
|
+
function hasParsedOptionValue(state, valueParser) {
|
|
12
|
+
if (valueParser != null) return isDeferredParseState(state) || isDependencySourceState(state) || state != null && "success" in state && state.success;
|
|
13
|
+
return state != null && "success" in state && state.success && state.value === true;
|
|
14
|
+
}
|
|
11
15
|
/**
|
|
12
16
|
* Helper function to create the appropriate state for an option value.
|
|
13
17
|
* - If the value parser is a DerivedValueParser, wraps the result in a DeferredParseState
|
|
@@ -354,8 +358,7 @@ function option(...args) {
|
|
|
354
358
|
consumed: context.buffer.slice(0, 1)
|
|
355
359
|
};
|
|
356
360
|
if (optionNames$1.includes(context.buffer[0])) {
|
|
357
|
-
|
|
358
|
-
if (hasValue) return {
|
|
361
|
+
if (hasParsedOptionValue(context.state, valueParser)) return {
|
|
359
362
|
success: false,
|
|
360
363
|
consumed: 1,
|
|
361
364
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${optionName(context.buffer[0])} cannot be used multiple times.`
|
|
@@ -401,7 +404,7 @@ function option(...args) {
|
|
|
401
404
|
const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => name.startsWith("/") ? `${name}:` : `${name}=`);
|
|
402
405
|
for (const prefix of prefixes) {
|
|
403
406
|
if (!context.buffer[0].startsWith(prefix)) continue;
|
|
404
|
-
if (context.state
|
|
407
|
+
if (hasParsedOptionValue(context.state, valueParser)) {
|
|
405
408
|
const optionName$1 = prefix.slice(0, -1);
|
|
406
409
|
return {
|
|
407
410
|
success: false,
|
|
@@ -439,7 +442,7 @@ function option(...args) {
|
|
|
439
442
|
const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/));
|
|
440
443
|
for (const shortOption of shortOptions) {
|
|
441
444
|
if (!context.buffer[0].startsWith(shortOption)) continue;
|
|
442
|
-
if (context.state
|
|
445
|
+
if (hasParsedOptionValue(context.state, valueParser)) return {
|
|
443
446
|
success: false,
|
|
444
447
|
consumed: 1,
|
|
445
448
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(shortOption) : options.errors.duplicate : message`${optionName(shortOption)} cannot be used multiple times.`
|