@optique/core 1.0.11-dev.2640 → 1.0.11-dev.2656

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.
@@ -1,5 +1,6 @@
1
1
  const require_annotations = require('./internal/annotations.cjs');
2
2
  const require_message = require('./message.cjs');
3
+ const require_passthrough = require('./internal/passthrough.cjs');
3
4
  const require_validate = require('./validate.cjs');
4
5
  const require_usage = require('./usage.cjs');
5
6
  const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
@@ -137,6 +138,7 @@ function constant(value) {
137
138
  return { fragments: [] };
138
139
  }
139
140
  };
141
+ require_passthrough.defineKnownCompletion(result, (state) => require_annotation_state.normalizeInjectedAnnotationState(state));
140
142
  Object.defineProperty(result, "placeholder", {
141
143
  value,
142
144
  configurable: true,
@@ -958,7 +960,7 @@ function argument(valueParser, options = {}) {
958
960
  const syncValueParser = valueParser;
959
961
  const dependencyMetadata = require_dependency_metadata.extractDependencyMetadata(valueParser);
960
962
  const formatInvalidValueError = (error) => options.errors?.invalidValue ? typeof options.errors.invalidValue === "function" ? options.errors.invalidValue(error) : options.errors.invalidValue : require_message.message`${require_message.metavar(valueParser.metavar)}: ${error}`;
961
- const optionPattern = /^--?[a-z0-9-]+$/i;
963
+ const optionPattern = /^(?!--=)(--?[a-z0-9-]+)(?:=|$)/i;
962
964
  const term = {
963
965
  type: "argument",
964
966
  metavar: valueParser.metavar,
@@ -982,14 +984,15 @@ function argument(valueParser, options = {}) {
982
984
  };
983
985
  let i = 0;
984
986
  let optionsTerminated = context.optionsTerminated;
985
- if (!optionsTerminated) {
986
- if (context.buffer[i] === "--") {
987
- optionsTerminated = true;
988
- i++;
989
- } else if (context.buffer[i].match(optionPattern)) return {
987
+ if (!optionsTerminated) if (context.buffer[i] === "--") {
988
+ optionsTerminated = true;
989
+ i++;
990
+ } else {
991
+ const optionMatch = context.buffer[i].match(optionPattern);
992
+ if (optionMatch != null) return {
990
993
  success: false,
991
994
  consumed: i,
992
- error: require_message.message`Expected an argument, but got an option: ${require_message.optionName(context.buffer[i])}.`
995
+ error: require_message.message`Expected an argument, but got an option: ${require_message.optionName(optionMatch[1])}.`
993
996
  };
994
997
  }
995
998
  if (context.buffer.length < i + 1) return {
@@ -1434,6 +1437,22 @@ function command(name, parser, options = {}) {
1434
1437
  configurable: true,
1435
1438
  enumerable: false
1436
1439
  });
1440
+ require_passthrough.definePassThroughPriority(result, [parser], (state, token) => {
1441
+ const active = normalizeCommandState(state);
1442
+ if (active == null) return void 0;
1443
+ const childState = active[0] === "matched" ? parser.initialState : active[1];
1444
+ return require_passthrough.getPassThroughPriority(parser, getCommandParseChildState(state, childState, parser), token);
1445
+ });
1446
+ require_passthrough.defineOptionMatch(result, (state, token) => {
1447
+ const active = normalizeCommandState(state);
1448
+ if (active == null) return void 0;
1449
+ const childState = active[0] === "matched" ? parser.initialState : active[1];
1450
+ const match = require_passthrough.getOptionMatch(parser, getCommandParseChildState(state, childState, parser), token);
1451
+ return match == null ? void 0 : {
1452
+ ...match,
1453
+ continuesCommand: true
1454
+ };
1455
+ });
1437
1456
  return result;
1438
1457
  }
1439
1458
  /**
@@ -1486,7 +1505,7 @@ function passThrough(options = {}) {
1486
1505
  const format = options.format ?? "equalsOnly";
1487
1506
  const optionPattern = /^-[a-z0-9-]|^--[a-z0-9-]+/i;
1488
1507
  const equalsOptionPattern = /^--[a-z0-9-]+=/i;
1489
- return {
1508
+ const result = {
1490
1509
  $valueType: [],
1491
1510
  $stateType: [],
1492
1511
  mode: "sync",
@@ -1504,6 +1523,8 @@ function passThrough(options = {}) {
1504
1523
  consumed: 0,
1505
1524
  error: require_message.message`No input to pass through.`
1506
1525
  };
1526
+ const failure = require_passthrough.getPassThroughFailure(context, this?.priority ?? -10);
1527
+ if (failure != null) return failure.failure;
1507
1528
  const token = context.buffer[0];
1508
1529
  if (format === "greedy") {
1509
1530
  const captured = [...context.buffer];
@@ -1615,6 +1636,12 @@ function passThrough(options = {}) {
1615
1636
  return `passThrough(${format})`;
1616
1637
  }
1617
1638
  };
1639
+ require_passthrough.definePassThroughPriority(result, [result], (_state, token) => {
1640
+ if (token == null || format === "greedy") return result.priority;
1641
+ const accepts = format === "equalsOnly" ? equalsOptionPattern.test(token) : format === "nextToken" && optionPattern.test(token);
1642
+ return accepts ? result.priority : void 0;
1643
+ });
1644
+ return result;
1618
1645
  }
1619
1646
 
1620
1647
  //#endregion
@@ -1,5 +1,6 @@
1
1
  import { annotateFreshArray, getAnnotations } from "./internal/annotations.js";
2
2
  import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
3
+ import { defineKnownCompletion, defineOptionMatch, definePassThroughPriority, getOptionMatch, getPassThroughFailure, getPassThroughPriority } from "./internal/passthrough.js";
3
4
  import { validateCommandNames, validateOptionNames } from "./validate.js";
4
5
  import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
5
6
  import { dispatchByMode, dispatchIterableByMode, wrapForMode } from "./internal/mode-dispatch.js";
@@ -137,6 +138,7 @@ function constant(value) {
137
138
  return { fragments: [] };
138
139
  }
139
140
  };
141
+ defineKnownCompletion(result, (state) => normalizeInjectedAnnotationState(state));
140
142
  Object.defineProperty(result, "placeholder", {
141
143
  value,
142
144
  configurable: true,
@@ -958,7 +960,7 @@ function argument(valueParser, options = {}) {
958
960
  const syncValueParser = valueParser;
959
961
  const dependencyMetadata = extractDependencyMetadata(valueParser);
960
962
  const formatInvalidValueError = (error) => options.errors?.invalidValue ? typeof options.errors.invalidValue === "function" ? options.errors.invalidValue(error) : options.errors.invalidValue : message`${metavar(valueParser.metavar)}: ${error}`;
961
- const optionPattern = /^--?[a-z0-9-]+$/i;
963
+ const optionPattern = /^(?!--=)(--?[a-z0-9-]+)(?:=|$)/i;
962
964
  const term = {
963
965
  type: "argument",
964
966
  metavar: valueParser.metavar,
@@ -982,14 +984,15 @@ function argument(valueParser, options = {}) {
982
984
  };
983
985
  let i = 0;
984
986
  let optionsTerminated = context.optionsTerminated;
985
- if (!optionsTerminated) {
986
- if (context.buffer[i] === "--") {
987
- optionsTerminated = true;
988
- i++;
989
- } else if (context.buffer[i].match(optionPattern)) return {
987
+ if (!optionsTerminated) if (context.buffer[i] === "--") {
988
+ optionsTerminated = true;
989
+ i++;
990
+ } else {
991
+ const optionMatch = context.buffer[i].match(optionPattern);
992
+ if (optionMatch != null) return {
990
993
  success: false,
991
994
  consumed: i,
992
- error: message`Expected an argument, but got an option: ${optionName(context.buffer[i])}.`
995
+ error: message`Expected an argument, but got an option: ${optionName(optionMatch[1])}.`
993
996
  };
994
997
  }
995
998
  if (context.buffer.length < i + 1) return {
@@ -1434,6 +1437,22 @@ function command(name, parser, options = {}) {
1434
1437
  configurable: true,
1435
1438
  enumerable: false
1436
1439
  });
1440
+ definePassThroughPriority(result, [parser], (state, token) => {
1441
+ const active = normalizeCommandState(state);
1442
+ if (active == null) return void 0;
1443
+ const childState = active[0] === "matched" ? parser.initialState : active[1];
1444
+ return getPassThroughPriority(parser, getCommandParseChildState(state, childState, parser), token);
1445
+ });
1446
+ defineOptionMatch(result, (state, token) => {
1447
+ const active = normalizeCommandState(state);
1448
+ if (active == null) return void 0;
1449
+ const childState = active[0] === "matched" ? parser.initialState : active[1];
1450
+ const match = getOptionMatch(parser, getCommandParseChildState(state, childState, parser), token);
1451
+ return match == null ? void 0 : {
1452
+ ...match,
1453
+ continuesCommand: true
1454
+ };
1455
+ });
1437
1456
  return result;
1438
1457
  }
1439
1458
  /**
@@ -1486,7 +1505,7 @@ function passThrough(options = {}) {
1486
1505
  const format = options.format ?? "equalsOnly";
1487
1506
  const optionPattern = /^-[a-z0-9-]|^--[a-z0-9-]+/i;
1488
1507
  const equalsOptionPattern = /^--[a-z0-9-]+=/i;
1489
- return {
1508
+ const result = {
1490
1509
  $valueType: [],
1491
1510
  $stateType: [],
1492
1511
  mode: "sync",
@@ -1504,6 +1523,8 @@ function passThrough(options = {}) {
1504
1523
  consumed: 0,
1505
1524
  error: message`No input to pass through.`
1506
1525
  };
1526
+ const failure = getPassThroughFailure(context, this?.priority ?? -10);
1527
+ if (failure != null) return failure.failure;
1507
1528
  const token = context.buffer[0];
1508
1529
  if (format === "greedy") {
1509
1530
  const captured = [...context.buffer];
@@ -1615,6 +1636,12 @@ function passThrough(options = {}) {
1615
1636
  return `passThrough(${format})`;
1616
1637
  }
1617
1638
  };
1639
+ definePassThroughPriority(result, [result], (_state, token) => {
1640
+ if (token == null || format === "greedy") return result.priority;
1641
+ const accepts = format === "equalsOnly" ? equalsOptionPattern.test(token) : format === "nextToken" && optionPattern.test(token);
1642
+ return accepts ? result.priority : void 0;
1643
+ });
1644
+ return result;
1618
1645
  }
1619
1646
 
1620
1647
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.11-dev.2640",
3
+ "version": "1.0.11-dev.2656",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",