@jals1212/pi-spaces-cli 0.6.1 → 0.6.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cli.js +29 -11
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ commands and options and a patch version fixes.
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 0.6.2
10
+
11
+ ### Fixed
12
+
13
+ - `pi-space --help <TAB>` (and `-h`) offers the commands with their summary,
14
+ `completion` included, so the help of a command is one Tab away.
15
+ - `--every` is completed in its own `target` group instead of among the space
16
+ names, since it is not a space.
17
+ - The completion text of the first `--help` says it also takes a command:
18
+ `print the help, or a command's: --help <command>`.
19
+
9
20
  ## 0.6.1
10
21
 
11
22
  ### Added
package/dist/cli.js CHANGED
@@ -239,8 +239,15 @@ const COMMANDS = {
239
239
  },
240
240
  };
241
241
 
242
+ /** --help after a command; GENERAL_OPTIONS has the --help that comes first. */
242
243
  const HELP_OPTION = { flag: "--help", alias: "-h", text: "the help of this command" };
243
244
 
245
+ /** The options that stand alone in first place, as completion describes them. */
246
+ const GENERAL_OPTIONS = [
247
+ ["--help", "print the help, or a command's: --help <command>"],
248
+ ["--version", "print the version"],
249
+ ];
250
+
244
251
  /** The help of one command: usage, what it does, arguments, options, the call options that apply, and examples. */
245
252
  function commandHelp(name ) {
246
253
  const help = COMMANDS[name];
@@ -284,7 +291,7 @@ export function parseCli(args ) {
284
291
  function parseCommand(args ) {
285
292
  const [first, ...rest] = args;
286
293
  if (first === undefined) return { kind: "picker" };
287
- if (isHelpFlag(first)) return rest.length === 0 ? { kind: "help" } : rest.length === 1 ? { kind: "command-help", command: rest[0] } : { kind: "usage" };
294
+ if (isHelpFlag(first)) return parseHelp(rest);
288
295
  if (first === "--version" || first === "-v") return { kind: "version" };
289
296
  if (Object.hasOwn(REPLACED, first)) return { kind: "replaced", option: first, instead: REPLACED[first ] };
290
297
  if (first.startsWith("-")) return { kind: "unknown-option", option: first };
@@ -308,6 +315,13 @@ function parseCommand(args ) {
308
315
  return { kind: "launch", name: first, args: rest };
309
316
  }
310
317
 
318
+ /** `--help` alone is the general help; `--help <command>` is that command's. */
319
+ function parseHelp(rest ) {
320
+ if (rest.length === 0) return { kind: "help" };
321
+ if (rest.length === 1) return { kind: "command-help", command: rest[0] };
322
+ return { kind: "usage" };
323
+ }
324
+
311
325
  /** `setup <name>` or `setup --every`: exactly one argument. */
312
326
  function parseSetup(rest ) {
313
327
  if (rest.length !== 1) return { kind: "usage" };
@@ -627,7 +641,7 @@ const ZSH_COMPLETION = [
627
641
  "#compdef pi-space",
628
642
  "# zsh completion for pi-space. Load it from .zshrc with: source <(pi-space completion zsh)",
629
643
  "_pi_space() {",
630
- " local -a lines cmds spaces profiles shells opts",
644
+ " local -a lines cmds spaces targets profiles shells opts",
631
645
  " local line group value text ret=1",
632
646
  ' lines=("${(@f)$(command "${words[1]}" __complete "${(@)words[2,CURRENT-1]}" 2>/dev/null)}")',
633
647
  ` if [[ "\${lines[1]}" == ${FILES} ]]; then`,
@@ -645,6 +659,7 @@ const ZSH_COMPLETION = [
645
659
  ' case "$group" in',
646
660
  ' command) cmds+=("$value:$text") ;;',
647
661
  ' space) spaces+=("$value:$text") ;;',
662
+ ' target) targets+=("$value:$text") ;;',
648
663
  ' profile) profiles+=("$value:$text") ;;',
649
664
  ' shell) shells+=("$value:$text") ;;',
650
665
  ' option) [[ "$PREFIX" == -* ]] && opts+=("$value:$text") ;;',
@@ -652,6 +667,7 @@ const ZSH_COMPLETION = [
652
667
  " done",
653
668
  " (( $#cmds )) && _describe -t commands 'command' cmds && ret=0",
654
669
  " (( $#spaces )) && _describe -t spaces 'space' spaces && ret=0",
670
+ " (( $#targets )) && _describe -t targets 'target' targets && ret=0",
655
671
  " (( $#profiles )) && _describe -t profiles 'profile' profiles && ret=0",
656
672
  " (( $#shells )) && _describe -t shells 'shell' shells && ret=0",
657
673
  " (( $#opts )) && _describe -t options 'option' opts && ret=0",
@@ -661,8 +677,8 @@ const ZSH_COMPLETION = [
661
677
  "",
662
678
  ].join("\n");
663
679
 
664
- /** The groups of a `__complete` line. */
665
-
680
+ /** The groups of a `__complete` line; `target` is --every, which stands in for a space name. */
681
+
666
682
 
667
683
  /** One `__complete` line; the description never holds a tab or a newline. */
668
684
  function candidate(group , value , text ) {
@@ -684,10 +700,10 @@ function complete(words , io ) {
684
700
  return io.exit(0);
685
701
  }
686
702
 
687
- /** The first-place commands: `completion` is left out (it still works typed in full). */
688
- function commandCandidates() {
703
+ /** The commands with their summary; in first place `completion` is left out (it still works typed in full), after --help it is not. */
704
+ function commandCandidates(withCompletion ) {
689
705
  return Object.entries(COMMANDS)
690
- .filter(([name]) => name !== "completion")
706
+ .filter(([name]) => withCompletion || name !== "completion")
691
707
  .map(([name, help]) => candidate("command", name, help.summary));
692
708
  }
693
709
 
@@ -696,7 +712,7 @@ function firstOptions(call , alone ) {
696
712
  const calls = Object.entries(CALL_OPTIONS)
697
713
  .filter(([, key]) => call[key] === undefined)
698
714
  .map(([flag, key]) => candidate("option", flag, CALL_HELP[key][1]));
699
- const general = alone ? [candidate("option", "--help", "print the help"), candidate("option", "--version", "print the version")] : [];
715
+ const general = alone ? GENERAL_OPTIONS.map(([flag, text]) => candidate("option", flag, text)) : [];
700
716
  return [...calls, ...general];
701
717
  }
702
718
 
@@ -707,7 +723,7 @@ function spaceCandidates(spaces , withBase ) {
707
723
 
708
724
  /** What follows a command word: its target, its own options and --help. */
709
725
  function commandArguments(command , spaces ) {
710
- const every = (text ) => candidate("space", "--every", text);
726
+ const every = (text ) => candidate("target", "--every", text);
711
727
  const options = [...COMMANDS[command].options, HELP_OPTION].map((option) => candidate("option", option.flag, option.text));
712
728
  switch (command) {
713
729
  case "remove":
@@ -740,8 +756,10 @@ function candidates(words , io ) {
740
756
  const { dir } = resolveSettings(call, io);
741
757
  const rest = words.slice(index);
742
758
  const spaces = listSpaces(dir);
743
- if (rest.length === 0) return [...commandCandidates(), ...spaceCandidates(spaces, true), ...firstOptions(call, index === 0)];
744
- if (rest.length > 1 || !Object.hasOwn(COMMANDS, rest[0])) return [];
759
+ if (rest.length === 0) return [...commandCandidates(false), ...spaceCandidates(spaces, true), ...firstOptions(call, index === 0)];
760
+ if (rest.length > 1) return [];
761
+ if (isHelpFlag(rest[0])) return commandCandidates(true);
762
+ if (!Object.hasOwn(COMMANDS, rest[0])) return [];
745
763
  return commandArguments(rest[0], spaces);
746
764
  }
747
765
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jals1212/pi-spaces-cli",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "The pi-space command: pick a space and start Pi in it. Companion to the Pi extension @jals1212/pi-spaces.",
5
5
  "license": "MIT",
6
6
  "author": "jals1212",