@qodalis/cli 2.0.0-rc.1 → 2.0.0-rc.3

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/public-api.mjs CHANGED
@@ -292,6 +292,13 @@ function reconcileArgs(tokens, descriptors) {
292
292
  }
293
293
  return { args, commandParts };
294
294
  }
295
+ function flagTakesNextWord(flag, descriptors) {
296
+ if (flag.hasEquals) return false;
297
+ const descriptor = findDescriptor(flag.name, descriptors);
298
+ if (descriptor) return descriptor.type !== "boolean";
299
+ const letters = flag.short ? expandShortFlags(flag.name, descriptors) : void 0;
300
+ return !!letters && letters[letters.length - 1].descriptor.type !== "boolean";
301
+ }
295
302
  function findDescriptor(name, descriptors) {
296
303
  if (!descriptors) return void 0;
297
304
  return descriptors.find(
@@ -511,7 +518,7 @@ var CliKeyValueStore_TOKEN = createCliToken("cli-key-value-store");
511
518
  var SyntaxHighlighterRegistry_TOKEN = createCliToken("syntax-highlighter-registry");
512
519
 
513
520
  // src/lib/version.ts
514
- var LIBRARY_VERSION = "2.0.0-rc.1";
521
+ var LIBRARY_VERSION = "2.0.0-rc.3";
515
522
  var API_VERSION = 2;
516
523
  var ANONYMOUS = "\0anonymous";
517
524
  function aliasOwner(context2) {
@@ -18284,19 +18291,20 @@ var CliCommandExecutor = class {
18284
18291
  const parsed = this.commandParser.parse(command2);
18285
18292
  let { commandName } = parsed;
18286
18293
  let parsedArgs = parsed.args;
18287
- const [mainCommand, ...other] = commandName.split(" ");
18288
- const chainCommands = other.map((c) => c.toLowerCase());
18289
18294
  const searchableProcessors = context2.contextProcessor ? context2.contextProcessor.processors ?? [] : this.registry.processors;
18295
+ const { words, descriptors } = this.commandWords(
18296
+ parsed.tokens,
18297
+ searchableProcessors
18298
+ );
18299
+ const [mainCommand = "", ...other] = words.length ? words : commandName.split(" ");
18300
+ const chainCommands = other.map((c) => c.toLowerCase());
18290
18301
  const processor = this.registry.findProcessorInCollection(
18291
18302
  mainCommand,
18292
18303
  chainCommands,
18293
18304
  searchableProcessors
18294
18305
  );
18295
- if (processor?.parameters?.length) {
18296
- const reconciled = reconcileArgs(
18297
- parsed.tokens,
18298
- processor.parameters
18299
- );
18306
+ if (processor && descriptors.length) {
18307
+ const reconciled = reconcileArgs(parsed.tokens, descriptors);
18300
18308
  parsedArgs = reconciled.args;
18301
18309
  commandName = reconciled.commandParts.join(" ");
18302
18310
  }
@@ -18590,6 +18598,37 @@ var CliCommandExecutor = class {
18590
18598
  * The text after the word that selected `processor`, which may be its
18591
18599
  * command or one of its aliases (e.g. `pkg rm guid` -> `guid`).
18592
18600
  */
18601
+ /**
18602
+ * Reads the words of a command left to right, matching each against the
18603
+ * sub-commands of the processor matched so far. A flag that takes a
18604
+ * value (by the parameters of the processors matched so far, nearest
18605
+ * first) consumes the word after it, so that word is neither a
18606
+ * sub-command nor part of the command's value.
18607
+ */
18608
+ commandWords(tokens, processors) {
18609
+ const words = [];
18610
+ let descriptors = [];
18611
+ let candidates = processors;
18612
+ for (let i = 0; i < tokens.length; i++) {
18613
+ const token = tokens[i];
18614
+ if (token.kind === "flag") {
18615
+ if (tokens[i + 1]?.kind === "word" && flagTakesNextWord(token, descriptors)) {
18616
+ i++;
18617
+ }
18618
+ continue;
18619
+ }
18620
+ words.push(token.value);
18621
+ const name = token.value.toLowerCase();
18622
+ const match = candidates?.find(
18623
+ (p) => p.command.toLowerCase() === name || p.aliases?.some((a) => a.toLowerCase() === name)
18624
+ );
18625
+ if (match) {
18626
+ descriptors = [...match.parameters ?? [], ...descriptors];
18627
+ }
18628
+ candidates = match?.processors?.length ? match.processors : void 0;
18629
+ }
18630
+ return { words, descriptors };
18631
+ }
18593
18632
  extractPositionalValue(commandName, processor) {
18594
18633
  const names = new Set(
18595
18634
  [processor.command, ...processor.aliases ?? []].map(