@kaynooo/cli-view 0.7.0 → 0.7.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 (2) hide show
  1. package/dist/view.js +81 -2
  2. package/package.json +5 -5
package/dist/view.js CHANGED
@@ -545,7 +545,7 @@ class Completing {
545
545
  }
546
546
  var completion = { active: false };
547
547
  var OUTPUT_OPTIONS = {
548
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
548
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
549
549
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
550
550
  };
551
551
  function applyOutput(color, plain, env = process10.env) {
@@ -751,6 +751,66 @@ import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs
751
751
  import { dirname as dirname3, join as join5 } from "path";
752
752
  import process14 from "process";
753
753
 
754
+ // ../kit/src/completions.ts
755
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
756
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
757
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
758
+ set -l current (commandline -ct)
759
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
760
+ if test "$line" = __files__
761
+ __fish_complete_path $current
762
+ else
763
+ echo $line
764
+ end
765
+ end
766
+ end`;
767
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
768
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
769
+ local -a lines
770
+ COMPREPLY=()
771
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
772
+ for line in "\${lines[@]}"; do
773
+ if [[ $line == __files__ ]]; then
774
+ COMPREPLY+=($(compgen -f -- "$cur"))
775
+ else
776
+ words+="\${line%%$'\\t'*}"$'\\n'
777
+ fi
778
+ done
779
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
780
+ }`;
781
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
782
+ local line
783
+ local -a described plain
784
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
785
+ if [[ $line == __files__ ]]; then
786
+ _files
787
+ elif [[ $line == *$'\\t'* ]]; then
788
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
789
+ else
790
+ plain+=("$line")
791
+ fi
792
+ done
793
+ (( \${#described} )) && _describe -V value described
794
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
795
+ return 0
796
+ }`;
797
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
798
+ if (shell === "fish")
799
+ return `${header}
800
+ ${FISH_FUNCTION}
801
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
802
+ `).join("")}`;
803
+ if (shell === "bash")
804
+ return `${header}
805
+ ${BASH_FUNCTION}
806
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
807
+ `;
808
+ return `${header}
809
+ ${ZSH_FUNCTION}
810
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
811
+ `;
812
+ }
813
+
754
814
  // ../kit/src/notify.ts
755
815
  import process12 from "process";
756
816
  var NOTIFY_AFTER_MS = 1e4;
@@ -824,7 +884,11 @@ var LEVEL_OPTIONS = {
824
884
  ...OUTPUT_OPTIONS,
825
885
  help: { type: "boolean", short: "h", description: "show this help" }
826
886
  };
827
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
887
+ var TOP_OPTIONS = {
888
+ ...LEVEL_OPTIONS,
889
+ version: { type: "boolean", short: "v", description: "print the version" },
890
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
891
+ };
828
892
  function printError(prefix, message, hint, cause) {
829
893
  const colors = paint(process14.stderr);
830
894
  const styled = takesControlCodes(process14.stderr);
@@ -904,6 +968,19 @@ async function leafCandidates(run, words) {
904
968
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
905
969
  return values === undefined ? [FILES] : values.map(candidateLine);
906
970
  }
971
+ var COMPLETIONS = "--completions";
972
+ function flagValue([flag = "", ...rest]) {
973
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
974
+ }
975
+ function printCompletionScript(name, args) {
976
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
977
+ if (shell === undefined || args.length !== 1) {
978
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
979
+ return 2;
980
+ }
981
+ console.log(completionScript(shell, [name]).trimEnd());
982
+ return 0;
983
+ }
907
984
  async function printCandidates(found) {
908
985
  for (const line of await found)
909
986
  console.log(line);
@@ -927,6 +1004,8 @@ function packageVersion(entry = Bun.main) {
927
1004
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
928
1005
  if (argv[0] === COMPLETE)
929
1006
  return printCandidates(leafCandidates(run, argv.slice(1)));
1007
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1008
+ return printCompletionScript(name, flagValue(argv));
930
1009
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
931
1010
  console.log(version ?? packageVersion());
932
1011
  return 0;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-view",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.7.2",
5
5
  "description": "view: markdown files and git diffs shown in the colours of the other @kaynooo CLIs, paged when long.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/view#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/view#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://git.kaynooo.fr/kaynooo/cli.git",
11
+ "url": "git+https://github.com/Kayno0o/cli.git",
12
12
  "directory": "packages/view"
13
13
  },
14
- "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
14
+ "bugs": "https://github.com/Kayno0o/cli/issues",
15
15
  "keywords": [
16
16
  "cli",
17
17
  "markdown",
@@ -35,6 +35,6 @@
35
35
  "view": "$npm_execpath src/view.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.40.0"
38
+ "@kaynooo/cli-kit": "0.41.1"
39
39
  }
40
40
  }