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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qodalis/cli",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.2",
4
4
  "description": "Framework-agnostic CLI engine for @qodalis terminal applications.",
5
5
  "author": "Nicolae Lupei, Qodalis Solutions",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "./assets/*": "./assets/*"
31
31
  },
32
32
  "dependencies": {
33
- "@qodalis/cli-core": "2.0.0-rc.1",
33
+ "@qodalis/cli-core": "2.0.0-rc.2",
34
34
  "@xterm/xterm": "^6.0.0",
35
35
  "@xterm/addon-fit": "^0.11.0",
36
36
  "@xterm/addon-web-links": "^0.12.0",
package/public-api.d.mts CHANGED
@@ -165,7 +165,7 @@ declare const CliKeyValueStore_TOKEN: any;
165
165
  */
166
166
  declare const SyntaxHighlighterRegistry_TOKEN: any;
167
167
 
168
- declare const LIBRARY_VERSION = "2.0.0-rc.1";
168
+ declare const LIBRARY_VERSION = "2.0.0-rc.2";
169
169
  declare const API_VERSION = 2;
170
170
 
171
171
  declare class CliAliasCommandProcessor implements ICliCommandProcessor {
@@ -1609,6 +1609,14 @@ declare class CliCommandExecutor implements ICliCommandExecutorService {
1609
1609
  * The text after the word that selected `processor`, which may be its
1610
1610
  * command or one of its aliases (e.g. `pkg rm guid` -> `guid`).
1611
1611
  */
1612
+ /**
1613
+ * Reads the words of a command left to right, matching each against the
1614
+ * sub-commands of the processor matched so far. A flag that takes a
1615
+ * value (by the parameters of the processors matched so far, nearest
1616
+ * first) consumes the word after it, so that word is neither a
1617
+ * sub-command nor part of the command's value.
1618
+ */
1619
+ private commandWords;
1612
1620
  private extractPositionalValue;
1613
1621
  private guardDenial;
1614
1622
  private processorOwnsParameter;
package/public-api.d.ts CHANGED
@@ -165,7 +165,7 @@ declare const CliKeyValueStore_TOKEN: any;
165
165
  */
166
166
  declare const SyntaxHighlighterRegistry_TOKEN: any;
167
167
 
168
- declare const LIBRARY_VERSION = "2.0.0-rc.1";
168
+ declare const LIBRARY_VERSION = "2.0.0-rc.2";
169
169
  declare const API_VERSION = 2;
170
170
 
171
171
  declare class CliAliasCommandProcessor implements ICliCommandProcessor {
@@ -1609,6 +1609,14 @@ declare class CliCommandExecutor implements ICliCommandExecutorService {
1609
1609
  * The text after the word that selected `processor`, which may be its
1610
1610
  * command or one of its aliases (e.g. `pkg rm guid` -> `guid`).
1611
1611
  */
1612
+ /**
1613
+ * Reads the words of a command left to right, matching each against the
1614
+ * sub-commands of the processor matched so far. A flag that takes a
1615
+ * value (by the parameters of the processors matched so far, nearest
1616
+ * first) consumes the word after it, so that word is neither a
1617
+ * sub-command nor part of the command's value.
1618
+ */
1619
+ private commandWords;
1612
1620
  private extractPositionalValue;
1613
1621
  private guardDenial;
1614
1622
  private processorOwnsParameter;
package/public-api.js CHANGED
@@ -293,6 +293,13 @@ function reconcileArgs(tokens, descriptors) {
293
293
  }
294
294
  return { args, commandParts };
295
295
  }
296
+ function flagTakesNextWord(flag, descriptors) {
297
+ if (flag.hasEquals) return false;
298
+ const descriptor = findDescriptor(flag.name, descriptors);
299
+ if (descriptor) return descriptor.type !== "boolean";
300
+ const letters = flag.short ? expandShortFlags(flag.name, descriptors) : void 0;
301
+ return !!letters && letters[letters.length - 1].descriptor.type !== "boolean";
302
+ }
296
303
  function findDescriptor(name, descriptors) {
297
304
  if (!descriptors) return void 0;
298
305
  return descriptors.find(
@@ -512,7 +519,7 @@ var CliKeyValueStore_TOKEN = cliCore.createCliToken("cli-key-value-store");
512
519
  var SyntaxHighlighterRegistry_TOKEN = cliCore.createCliToken("syntax-highlighter-registry");
513
520
 
514
521
  // src/lib/version.ts
515
- var LIBRARY_VERSION = "2.0.0-rc.1";
522
+ var LIBRARY_VERSION = "2.0.0-rc.2";
516
523
  var API_VERSION = 2;
517
524
  var ANONYMOUS = "\0anonymous";
518
525
  function aliasOwner(context2) {
@@ -18285,19 +18292,20 @@ var CliCommandExecutor = class {
18285
18292
  const parsed = this.commandParser.parse(command2);
18286
18293
  let { commandName } = parsed;
18287
18294
  let parsedArgs = parsed.args;
18288
- const [mainCommand, ...other] = commandName.split(" ");
18289
- const chainCommands = other.map((c) => c.toLowerCase());
18290
18295
  const searchableProcessors = context2.contextProcessor ? context2.contextProcessor.processors ?? [] : this.registry.processors;
18296
+ const { words, descriptors } = this.commandWords(
18297
+ parsed.tokens,
18298
+ searchableProcessors
18299
+ );
18300
+ const [mainCommand = "", ...other] = words.length ? words : commandName.split(" ");
18301
+ const chainCommands = other.map((c) => c.toLowerCase());
18291
18302
  const processor = this.registry.findProcessorInCollection(
18292
18303
  mainCommand,
18293
18304
  chainCommands,
18294
18305
  searchableProcessors
18295
18306
  );
18296
- if (processor?.parameters?.length) {
18297
- const reconciled = reconcileArgs(
18298
- parsed.tokens,
18299
- processor.parameters
18300
- );
18307
+ if (processor && descriptors.length) {
18308
+ const reconciled = reconcileArgs(parsed.tokens, descriptors);
18301
18309
  parsedArgs = reconciled.args;
18302
18310
  commandName = reconciled.commandParts.join(" ");
18303
18311
  }
@@ -18591,6 +18599,37 @@ var CliCommandExecutor = class {
18591
18599
  * The text after the word that selected `processor`, which may be its
18592
18600
  * command or one of its aliases (e.g. `pkg rm guid` -> `guid`).
18593
18601
  */
18602
+ /**
18603
+ * Reads the words of a command left to right, matching each against the
18604
+ * sub-commands of the processor matched so far. A flag that takes a
18605
+ * value (by the parameters of the processors matched so far, nearest
18606
+ * first) consumes the word after it, so that word is neither a
18607
+ * sub-command nor part of the command's value.
18608
+ */
18609
+ commandWords(tokens, processors) {
18610
+ const words = [];
18611
+ let descriptors = [];
18612
+ let candidates = processors;
18613
+ for (let i = 0; i < tokens.length; i++) {
18614
+ const token = tokens[i];
18615
+ if (token.kind === "flag") {
18616
+ if (tokens[i + 1]?.kind === "word" && flagTakesNextWord(token, descriptors)) {
18617
+ i++;
18618
+ }
18619
+ continue;
18620
+ }
18621
+ words.push(token.value);
18622
+ const name = token.value.toLowerCase();
18623
+ const match = candidates?.find(
18624
+ (p) => p.command.toLowerCase() === name || p.aliases?.some((a) => a.toLowerCase() === name)
18625
+ );
18626
+ if (match) {
18627
+ descriptors = [...match.parameters ?? [], ...descriptors];
18628
+ }
18629
+ candidates = match?.processors?.length ? match.processors : void 0;
18630
+ }
18631
+ return { words, descriptors };
18632
+ }
18594
18633
  extractPositionalValue(commandName, processor) {
18595
18634
  const names = new Set(
18596
18635
  [processor.command, ...processor.aliases ?? []].map(