@kaynooo/cli-base 0.11.0 → 0.12.0

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/README.md CHANGED
@@ -18,12 +18,12 @@ base --keep tests/NewTest.php -- vendor/bin/phpunit tests/NewTest.php
18
18
  - The exit code is the command's; a last stderr line says which ref ran, `base: ran at HEAD (1a2b3c4), exit 1`.
19
19
  - Exit codes of its own: 2 a usage error, an unknown ref or a refused command, 127 a command that cannot start.
20
20
 
21
- ## proof
21
+ ## base proof
22
22
 
23
- `proof` shows that a test fails before a change and passes after it, the check `base` makes by hand: it runs the command at HEAD (or `--ref <rev>`) in the same temporary worktree as `base`, then in the working tree, both captured.
23
+ `base proof` shows that a test fails before a change and passes after it, the check `base` makes by hand: it runs the command at HEAD (or `--ref <rev>`) in the same temporary worktree as `base`, then in the working tree, both captured.
24
24
 
25
25
  ```sh
26
- proof --keep tests/NewTest.php -- vendor/bin/phpunit tests/NewTest.php
26
+ base proof --keep tests/NewTest.php -- vendor/bin/phpunit tests/NewTest.php
27
27
  ```
28
28
 
29
29
  - `--ref` defaults to the merge base with `origin/main` when HEAD is on a branch other than `main` that is ahead of it, else HEAD; `--ref HEAD` forces the old default. The `--json` `ref` and the line name the commit it resolved to.
package/dist/cli.js CHANGED
@@ -500,7 +500,7 @@ class Completing {
500
500
  }
501
501
  var completion = { active: false };
502
502
  var OUTPUT_OPTIONS = {
503
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
503
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
504
504
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
505
505
  };
506
506
  function applyOutput(color, plain, env = process9.env) {
@@ -828,6 +828,66 @@ import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs
828
828
  import { dirname as dirname3, join as join5 } from "path";
829
829
  import process14 from "process";
830
830
 
831
+ // ../kit/src/completions.ts
832
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
833
+ 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'
834
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
835
+ set -l current (commandline -ct)
836
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
837
+ if test "$line" = __files__
838
+ __fish_complete_path $current
839
+ else
840
+ echo $line
841
+ end
842
+ end
843
+ end`;
844
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
845
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
846
+ local -a lines
847
+ COMPREPLY=()
848
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
849
+ for line in "\${lines[@]}"; do
850
+ if [[ $line == __files__ ]]; then
851
+ COMPREPLY+=($(compgen -f -- "$cur"))
852
+ else
853
+ words+="\${line%%$'\\t'*}"$'\\n'
854
+ fi
855
+ done
856
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
857
+ }`;
858
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
859
+ local line
860
+ local -a described plain
861
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
862
+ if [[ $line == __files__ ]]; then
863
+ _files
864
+ elif [[ $line == *$'\\t'* ]]; then
865
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
866
+ else
867
+ plain+=("$line")
868
+ fi
869
+ done
870
+ (( \${#described} )) && _describe -V value described
871
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
872
+ return 0
873
+ }`;
874
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
875
+ if (shell === "fish")
876
+ return `${header}
877
+ ${FISH_FUNCTION}
878
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
879
+ `).join("")}`;
880
+ if (shell === "bash")
881
+ return `${header}
882
+ ${BASH_FUNCTION}
883
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
884
+ `;
885
+ return `${header}
886
+ ${ZSH_FUNCTION}
887
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
888
+ `;
889
+ }
890
+
831
891
  // ../kit/src/notify.ts
832
892
  import process12 from "process";
833
893
  var NOTIFY_AFTER_MS = 1e4;
@@ -901,7 +961,11 @@ var LEVEL_OPTIONS = {
901
961
  ...OUTPUT_OPTIONS,
902
962
  help: { type: "boolean", short: "h", description: "show this help" }
903
963
  };
904
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
964
+ var TOP_OPTIONS = {
965
+ ...LEVEL_OPTIONS,
966
+ version: { type: "boolean", short: "v", description: "print the version" },
967
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
968
+ };
905
969
  async function commandRows(all, colors) {
906
970
  const commands = shown(all);
907
971
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1134,6 +1198,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
1134
1198
  }
1135
1199
  return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
1136
1200
  }
1201
+ var COMPLETIONS = "--completions";
1202
+ function flagValue([flag = "", ...rest]) {
1203
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1204
+ }
1205
+ function printCompletionScript(name, args) {
1206
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1207
+ if (shell === undefined || args.length !== 1) {
1208
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1209
+ return 2;
1210
+ }
1211
+ console.log(completionScript(shell, [name]).trimEnd());
1212
+ return 0;
1213
+ }
1137
1214
  async function printCandidates(found) {
1138
1215
  for (const line of await found)
1139
1216
  console.log(line);
@@ -1158,6 +1235,8 @@ async function runCli(cli, argv = scriptArgs()) {
1158
1235
  const version = cli.version ?? packageVersion();
1159
1236
  if (argv[0] === COMPLETE)
1160
1237
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1238
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1239
+ return printCompletionScript(cli.name, flagValue(argv));
1161
1240
  const started = performance.now();
1162
1241
  const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
1163
1242
  const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
@@ -1184,28 +1263,6 @@ function commandPath(scope, argv) {
1184
1263
  }
1185
1264
  return path.length === 0 ? undefined : path.join(" ");
1186
1265
  }
1187
- async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1188
- if (argv[0] === COMPLETE)
1189
- return printCandidates(leafCandidates(run, argv.slice(1)));
1190
- if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
1191
- console.log(version ?? packageVersion());
1192
- return 0;
1193
- }
1194
- let code;
1195
- const started = performance.now();
1196
- try {
1197
- code = await run(argv);
1198
- } catch (error) {
1199
- code = reportThrown(name, error, redact, wantsJson(argv));
1200
- }
1201
- notifyEnd(name, code, performance.now() - started);
1202
- if (usage !== false) {
1203
- try {
1204
- recordUsage(usageEntry(name, undefined, argv, code));
1205
- } catch {}
1206
- }
1207
- return code;
1208
- }
1209
1266
  // ../kit/src/folders.ts
1210
1267
  var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1211
1268
  // ../kit/src/secrets.ts
@@ -1488,7 +1545,7 @@ ${USAGE}`);
1488
1545
 
1489
1546
  // src/proof.ts
1490
1547
  import process18 from "process";
1491
- var USAGE2 = `proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--timeout <duration>] [--no-link] [--json] -- <command> [args...]: runs the command at HEAD or another ref in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
1548
+ var USAGE2 = `base proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--timeout <duration>] [--no-link] [--json] -- <command> [args...]: runs the command at HEAD or another ref in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
1492
1549
 
1493
1550
  The ref defaults to the merge base with the default branch of origin (origin/main unless origin/HEAD names another) when HEAD is on a branch ahead of it, else HEAD. --runs <n> runs the command n times now, for a flaky test, and every run must pass. --timeout kills a run that lasts longer (a hung test), which says nothing about the change and ends with exit 2.`;
1494
1551
  var EXITS = [[0, "the command fails before and passes in every run now"], [1, "it passes before too, fails in any run now, or passes before and fails now"], [2, "a usage error, an unknown ref, a command that cannot start, ends with exit 126, 127, 125 or a signal, or runs past --timeout"], [130, "interrupted (128 plus the signal)"]];
@@ -1529,7 +1586,7 @@ function describe(outcome, at, now) {
1529
1586
  }
1530
1587
  async function proof(argv) {
1531
1588
  const bare = argv[0] !== undefined && !argv[0].startsWith("-");
1532
- const parsed = parse(bare ? [] : argv, USAGE2, OPTIONS2, { rest: true, exits: EXITS, replaces: "running a test, stashing the change and running it again", examples: [["proof --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the new test fails at HEAD and passes now"], ["proof --ref v1.2.0 --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the same against a release"]] });
1589
+ const parsed = parse(bare ? [] : argv, USAGE2, OPTIONS2, { rest: true, exits: EXITS, replaces: "running a test, stashing the change and running it again", examples: [["base proof --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the new test fails at HEAD and passes now"], ["base proof --ref v1.2.0 --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the same against a release"]] });
1533
1590
  const given = bare ? argv : parsed.rest ?? [];
1534
1591
  if (given.length === 0 || parsed.positionals.length > 0)
1535
1592
  fail(`give the command after --
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-base",
3
3
  "type": "module",
4
- "version": "0.11.0",
4
+ "version": "0.12.0",
5
5
  "description": "base: a command run at HEAD or another ref in a temporary worktree, the working tree left untouched.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
8
- "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/base#readme",
8
+ "homepage": "https://github.com/Kayno0o/cli/tree/main/packages/base#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/base"
13
13
  },
14
- "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
14
+ "bugs": "https://github.com/Kayno0o/cli/issues",
15
15
  "keywords": [
16
16
  "claude-code",
17
17
  "cli",
@@ -20,8 +20,7 @@
20
20
  "stash"
21
21
  ],
22
22
  "bin": {
23
- "base": "./dist/cli.js",
24
- "proof": "./dist/proof-cli.js"
23
+ "base": "./dist/cli.js"
25
24
  },
26
25
  "files": [
27
26
  "dist"
@@ -33,11 +32,10 @@
33
32
  "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
34
33
  },
35
34
  "scripts": {
36
- "build": "$npm_execpath build src/cli.ts src/proof-cli.ts --target bun --outdir dist",
37
- "base": "$npm_execpath src/cli.ts",
38
- "proof": "$npm_execpath src/proof-cli.ts"
35
+ "build": "$npm_execpath build src/cli.ts --target bun --outdir dist",
36
+ "base": "$npm_execpath src/cli.ts"
39
37
  },
40
38
  "devDependencies": {
41
- "@kaynooo/cli-kit": "0.39.0"
39
+ "@kaynooo/cli-kit": "0.41.0"
42
40
  }
43
41
  }