@kaynooo/cli-probe 0.4.1 → 0.4.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.
Files changed (2) hide show
  1. package/dist/probe.js +81 -2
  2. package/package.json +5 -5
package/dist/probe.js CHANGED
@@ -566,7 +566,7 @@ class Completing {
566
566
  }
567
567
  var completion = { active: false };
568
568
  var OUTPUT_OPTIONS = {
569
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
569
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
570
570
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
571
571
  };
572
572
  function applyOutput(color, plain, env = process9.env) {
@@ -772,6 +772,66 @@ import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs
772
772
  import { dirname as dirname3, join as join5 } from "path";
773
773
  import process13 from "process";
774
774
 
775
+ // ../kit/src/completions.ts
776
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
777
+ 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'
778
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
779
+ set -l current (commandline -ct)
780
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
781
+ if test "$line" = __files__
782
+ __fish_complete_path $current
783
+ else
784
+ echo $line
785
+ end
786
+ end
787
+ end`;
788
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
789
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
790
+ local -a lines
791
+ COMPREPLY=()
792
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
793
+ for line in "\${lines[@]}"; do
794
+ if [[ $line == __files__ ]]; then
795
+ COMPREPLY+=($(compgen -f -- "$cur"))
796
+ else
797
+ words+="\${line%%$'\\t'*}"$'\\n'
798
+ fi
799
+ done
800
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
801
+ }`;
802
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
803
+ local line
804
+ local -a described plain
805
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
806
+ if [[ $line == __files__ ]]; then
807
+ _files
808
+ elif [[ $line == *$'\\t'* ]]; then
809
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
810
+ else
811
+ plain+=("$line")
812
+ fi
813
+ done
814
+ (( \${#described} )) && _describe -V value described
815
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
816
+ return 0
817
+ }`;
818
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
819
+ if (shell === "fish")
820
+ return `${header}
821
+ ${FISH_FUNCTION}
822
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
823
+ `).join("")}`;
824
+ if (shell === "bash")
825
+ return `${header}
826
+ ${BASH_FUNCTION}
827
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
828
+ `;
829
+ return `${header}
830
+ ${ZSH_FUNCTION}
831
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
832
+ `;
833
+ }
834
+
775
835
  // ../kit/src/notify.ts
776
836
  import process11 from "process";
777
837
  var NOTIFY_AFTER_MS = 1e4;
@@ -845,7 +905,11 @@ var LEVEL_OPTIONS = {
845
905
  ...OUTPUT_OPTIONS,
846
906
  help: { type: "boolean", short: "h", description: "show this help" }
847
907
  };
848
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
908
+ var TOP_OPTIONS = {
909
+ ...LEVEL_OPTIONS,
910
+ version: { type: "boolean", short: "v", description: "print the version" },
911
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
912
+ };
849
913
  function printError(prefix, message, hint, cause) {
850
914
  const colors = paint(process13.stderr);
851
915
  const styled = takesControlCodes(process13.stderr);
@@ -925,6 +989,19 @@ async function leafCandidates(run, words) {
925
989
  const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
926
990
  return values === undefined ? [FILES] : values.map(candidateLine);
927
991
  }
992
+ var COMPLETIONS = "--completions";
993
+ function flagValue([flag = "", ...rest]) {
994
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
995
+ }
996
+ function printCompletionScript(name, args) {
997
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
998
+ if (shell === undefined || args.length !== 1) {
999
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1000
+ return 2;
1001
+ }
1002
+ console.log(completionScript(shell, [name]).trimEnd());
1003
+ return 0;
1004
+ }
928
1005
  async function printCandidates(found) {
929
1006
  for (const line of await found)
930
1007
  console.log(line);
@@ -948,6 +1025,8 @@ function packageVersion(entry = Bun.main) {
948
1025
  async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
949
1026
  if (argv[0] === COMPLETE)
950
1027
  return printCandidates(leafCandidates(run, argv.slice(1)));
1028
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1029
+ return printCompletionScript(name, flagValue(argv));
951
1030
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
952
1031
  console.log(version ?? packageVersion());
953
1032
  return 0;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-probe",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "description": "probe: a site's HTTP version, redirect chain, timings, addresses, TLS certificate and notable headers in one call, with warnings.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/probe#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/probe#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/probe"
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
  "http",
@@ -35,6 +35,6 @@
35
35
  "probe": "$npm_execpath src/probe.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.39.0"
38
+ "@kaynooo/cli-kit": "0.41.1"
39
39
  }
40
40
  }