@kaynooo/cli-workspace 0.10.1 → 0.11.1
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/dist/audit-cli.js +340 -77
- package/dist/cli.js +456 -137
- package/dist/repos-cli.js +210 -72
- package/dist/sweep-cli.js +271 -77
- package/package.json +2 -2
package/dist/repos-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/repos-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -492,24 +492,20 @@ function printJson(value) {
|
|
|
492
492
|
|
|
493
493
|
// ../kit/src/help.ts
|
|
494
494
|
import process8 from "process";
|
|
495
|
-
var OPTIONAL =
|
|
495
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
496
496
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
497
497
|
var FULL_STOP = /\.$/;
|
|
498
498
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
499
499
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
500
500
|
}
|
|
501
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
502
|
-
return [usageLine(usage, colors),
|
|
501
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
502
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
503
503
|
`);
|
|
504
504
|
}
|
|
505
505
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
506
506
|
if (exits.length === 0)
|
|
507
507
|
return [];
|
|
508
|
-
|
|
509
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
510
|
-
}
|
|
511
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
512
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
508
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
513
509
|
}
|
|
514
510
|
function wantsHelpJson(env = process8.env) {
|
|
515
511
|
return env.KIT_HELP === "json";
|
|
@@ -535,29 +531,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
535
531
|
return [];
|
|
536
532
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
537
533
|
}
|
|
534
|
+
var MAX_INLINE_CHOICES = 24;
|
|
538
535
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
539
536
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
540
537
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
541
|
-
const
|
|
538
|
+
const choices = option.choices?.join("|");
|
|
539
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
540
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
542
541
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
543
542
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
544
|
-
|
|
543
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
544
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
545
545
|
});
|
|
546
546
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
547
547
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
548
548
|
}
|
|
549
549
|
|
|
550
550
|
// ../kit/src/text.ts
|
|
551
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
552
551
|
function distance(a, b) {
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
const left = [...a];
|
|
553
|
+
const right = [...b];
|
|
554
|
+
let before = [];
|
|
555
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
556
|
+
for (const [i, x] of left.entries()) {
|
|
555
557
|
const current = [i + 1];
|
|
556
|
-
for (const [j,
|
|
557
|
-
|
|
558
|
+
for (const [j, y] of right.entries()) {
|
|
559
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
560
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
561
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
562
|
+
current.push(cost);
|
|
563
|
+
}
|
|
564
|
+
before = previous;
|
|
558
565
|
previous = current;
|
|
559
566
|
}
|
|
560
|
-
return previous[
|
|
567
|
+
return previous[right.length] ?? 0;
|
|
561
568
|
}
|
|
562
569
|
function closest(name, names) {
|
|
563
570
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -624,7 +631,7 @@ class Completing {
|
|
|
624
631
|
}
|
|
625
632
|
var completion = { active: false };
|
|
626
633
|
var OUTPUT_OPTIONS = {
|
|
627
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
634
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
628
635
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
629
636
|
};
|
|
630
637
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -796,9 +803,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
796
803
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
797
804
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
798
805
|
}
|
|
806
|
+
// ../kit/src/argv.ts
|
|
807
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
808
|
+
import { resolve as resolve3 } from "path";
|
|
809
|
+
import process10 from "process";
|
|
810
|
+
function commandLine() {
|
|
811
|
+
try {
|
|
812
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
813
|
+
} catch {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function realPath(word) {
|
|
818
|
+
try {
|
|
819
|
+
return realpathSync(resolve3(word));
|
|
820
|
+
} catch {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
825
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
826
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
827
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
828
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
829
|
+
}
|
|
799
830
|
// ../kit/src/process.ts
|
|
800
831
|
import { constants } from "os";
|
|
801
|
-
import
|
|
832
|
+
import process11 from "process";
|
|
802
833
|
var KILL_GRACE_MS = 2000;
|
|
803
834
|
function exitCodeOf(code, signal) {
|
|
804
835
|
if (code !== null)
|
|
@@ -818,7 +849,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
818
849
|
return;
|
|
819
850
|
try {
|
|
820
851
|
if (grouped)
|
|
821
|
-
|
|
852
|
+
process11.kill(-proc.pid, killing);
|
|
822
853
|
else
|
|
823
854
|
proc.kill(killing);
|
|
824
855
|
} catch {}
|
|
@@ -893,10 +924,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
893
924
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
894
925
|
|
|
895
926
|
// ../kit/src/tool.ts
|
|
896
|
-
import
|
|
927
|
+
import process12 from "process";
|
|
897
928
|
function cwdGone() {
|
|
898
929
|
try {
|
|
899
|
-
|
|
930
|
+
process12.cwd();
|
|
900
931
|
return false;
|
|
901
932
|
} catch {
|
|
902
933
|
return true;
|
|
@@ -918,7 +949,7 @@ function spawnFailure(command, error) {
|
|
|
918
949
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
919
950
|
let ran;
|
|
920
951
|
try {
|
|
921
|
-
ran = await runCommand(argv, { env:
|
|
952
|
+
ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
922
953
|
} catch (error) {
|
|
923
954
|
throw spawnFailure(label, error);
|
|
924
955
|
}
|
|
@@ -933,15 +964,93 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
933
964
|
return { code: ran.code, ...streams };
|
|
934
965
|
}
|
|
935
966
|
// ../kit/src/cli.ts
|
|
936
|
-
import { readFileSync as
|
|
967
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
937
968
|
import { dirname as dirname3, join as join5 } from "path";
|
|
969
|
+
import process15 from "process";
|
|
970
|
+
|
|
971
|
+
// ../kit/src/completions.ts
|
|
972
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
973
|
+
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'
|
|
974
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
975
|
+
set -l current (commandline -ct)
|
|
976
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
977
|
+
if test "$line" = __files__
|
|
978
|
+
__fish_complete_path $current
|
|
979
|
+
else
|
|
980
|
+
echo $line
|
|
981
|
+
end
|
|
982
|
+
end
|
|
983
|
+
end`;
|
|
984
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
985
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
986
|
+
local -a lines
|
|
987
|
+
COMPREPLY=()
|
|
988
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
989
|
+
for line in "\${lines[@]}"; do
|
|
990
|
+
if [[ $line == __files__ ]]; then
|
|
991
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
992
|
+
else
|
|
993
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
994
|
+
fi
|
|
995
|
+
done
|
|
996
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
997
|
+
}`;
|
|
998
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
999
|
+
local line
|
|
1000
|
+
local -a described plain
|
|
1001
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1002
|
+
if [[ $line == __files__ ]]; then
|
|
1003
|
+
_files
|
|
1004
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1005
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1006
|
+
else
|
|
1007
|
+
plain+=("$line")
|
|
1008
|
+
fi
|
|
1009
|
+
done
|
|
1010
|
+
(( \${#described} )) && _describe -V value described
|
|
1011
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1012
|
+
return 0
|
|
1013
|
+
}`;
|
|
1014
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1015
|
+
if (shell === "fish")
|
|
1016
|
+
return `${header}
|
|
1017
|
+
${FISH_FUNCTION}
|
|
1018
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1019
|
+
`).join("")}`;
|
|
1020
|
+
if (shell === "bash")
|
|
1021
|
+
return `${header}
|
|
1022
|
+
${BASH_FUNCTION}
|
|
1023
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1024
|
+
`;
|
|
1025
|
+
return `${header}
|
|
1026
|
+
${ZSH_FUNCTION}
|
|
1027
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1028
|
+
`;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// ../kit/src/notify.ts
|
|
938
1032
|
import process13 from "process";
|
|
1033
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1034
|
+
var CANCELLED = 130;
|
|
1035
|
+
function base64(text) {
|
|
1036
|
+
return Buffer.from(text).toString("base64");
|
|
1037
|
+
}
|
|
1038
|
+
function notification(title, body, env = process13.env) {
|
|
1039
|
+
const id = `kit${process13.pid}`;
|
|
1040
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1041
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1042
|
+
}
|
|
1043
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1044
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1045
|
+
return;
|
|
1046
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1047
|
+
}
|
|
939
1048
|
|
|
940
1049
|
// ../kit/src/usage.ts
|
|
941
1050
|
import { appendFileSync, mkdirSync } from "fs";
|
|
942
1051
|
import { homedir as homedir3 } from "os";
|
|
943
1052
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
944
|
-
import
|
|
1053
|
+
import process14 from "process";
|
|
945
1054
|
|
|
946
1055
|
// ../kit/src/logs.ts
|
|
947
1056
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -955,14 +1064,14 @@ var usageError;
|
|
|
955
1064
|
function noteUsageError(message) {
|
|
956
1065
|
usageError = message;
|
|
957
1066
|
}
|
|
958
|
-
function stateHome(env =
|
|
1067
|
+
function stateHome(env = process14.env) {
|
|
959
1068
|
const dir = env.XDG_STATE_HOME;
|
|
960
1069
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
961
1070
|
}
|
|
962
|
-
function usagePath(env =
|
|
1071
|
+
function usagePath(env = process14.env) {
|
|
963
1072
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
964
1073
|
}
|
|
965
|
-
function usageRecorded(env =
|
|
1074
|
+
function usageRecorded(env = process14.env) {
|
|
966
1075
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
967
1076
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
968
1077
|
}
|
|
@@ -976,7 +1085,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
976
1085
|
usageError = undefined;
|
|
977
1086
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
978
1087
|
}
|
|
979
|
-
function recordUsage(entry, env =
|
|
1088
|
+
function recordUsage(entry, env = process14.env) {
|
|
980
1089
|
if (!usageRecorded(env))
|
|
981
1090
|
return;
|
|
982
1091
|
try {
|
|
@@ -992,7 +1101,11 @@ var LEVEL_OPTIONS = {
|
|
|
992
1101
|
...OUTPUT_OPTIONS,
|
|
993
1102
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
994
1103
|
};
|
|
995
|
-
var TOP_OPTIONS = {
|
|
1104
|
+
var TOP_OPTIONS = {
|
|
1105
|
+
...LEVEL_OPTIONS,
|
|
1106
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1107
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1108
|
+
};
|
|
996
1109
|
async function commandRows(all, colors) {
|
|
997
1110
|
const commands = shown(all);
|
|
998
1111
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1053,7 +1166,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1053
1166
|
header(colors, summary),
|
|
1054
1167
|
"",
|
|
1055
1168
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1056
|
-
...replacesRows(replaces, colors),
|
|
1057
1169
|
"",
|
|
1058
1170
|
...await commandRows(commands, colors),
|
|
1059
1171
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1067,8 +1179,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1067
1179
|
`);
|
|
1068
1180
|
}
|
|
1069
1181
|
function printError(prefix, message, hint, cause) {
|
|
1070
|
-
const colors = paint(
|
|
1071
|
-
const styled = takesControlCodes(
|
|
1182
|
+
const colors = paint(process15.stderr);
|
|
1183
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1072
1184
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1073
1185
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1074
1186
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1111,11 +1223,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1111
1223
|
}
|
|
1112
1224
|
}
|
|
1113
1225
|
if (name === undefined && level.path.length > 1) {
|
|
1114
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1226
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1115
1227
|
return 2;
|
|
1116
1228
|
}
|
|
1117
1229
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1118
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1230
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1119
1231
|
return 0;
|
|
1120
1232
|
}
|
|
1121
1233
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1171,24 +1283,24 @@ function candidateLine(candidate) {
|
|
|
1171
1283
|
}
|
|
1172
1284
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1173
1285
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1174
|
-
|
|
1286
|
+
const typed = [];
|
|
1175
1287
|
let at = 0;
|
|
1176
1288
|
while (at < before.length) {
|
|
1177
1289
|
const word = before[at];
|
|
1178
1290
|
if (word === "--") {
|
|
1179
|
-
|
|
1291
|
+
typed.push(...before.slice(at + 1));
|
|
1180
1292
|
break;
|
|
1181
1293
|
}
|
|
1182
1294
|
if (!word.startsWith("-"))
|
|
1183
|
-
|
|
1295
|
+
typed.push(word);
|
|
1184
1296
|
else if (takesValue(word))
|
|
1185
1297
|
at++;
|
|
1186
1298
|
at++;
|
|
1187
1299
|
}
|
|
1188
1300
|
const last = positionals.at(-1);
|
|
1189
|
-
if (
|
|
1190
|
-
return positionals[
|
|
1191
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1301
|
+
if (typed.length < positionals.length)
|
|
1302
|
+
return { name: positionals[typed.length], typed };
|
|
1303
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1192
1304
|
}
|
|
1193
1305
|
async function leafCandidates(run, words) {
|
|
1194
1306
|
const completing = await completingOf(run);
|
|
@@ -1196,12 +1308,12 @@ async function leafCandidates(run, words) {
|
|
|
1196
1308
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1197
1309
|
const flag = words.at(-2);
|
|
1198
1310
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1311
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1199
1312
|
if (option?.type === "string") {
|
|
1200
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1313
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1201
1314
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1202
1315
|
}
|
|
1203
|
-
const
|
|
1204
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1316
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1205
1317
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1206
1318
|
}
|
|
1207
1319
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1226,15 +1338,32 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1226
1338
|
}
|
|
1227
1339
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1228
1340
|
}
|
|
1341
|
+
var COMPLETIONS = "--completions";
|
|
1342
|
+
function flagValue([flag = "", ...rest]) {
|
|
1343
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1344
|
+
}
|
|
1345
|
+
function printCompletionScript(name, args) {
|
|
1346
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1347
|
+
if (shell === undefined || args.length !== 1) {
|
|
1348
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1349
|
+
return 2;
|
|
1350
|
+
}
|
|
1351
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1352
|
+
return 0;
|
|
1353
|
+
}
|
|
1229
1354
|
async function printCandidates(found) {
|
|
1230
1355
|
for (const line of await found)
|
|
1231
1356
|
console.log(line);
|
|
1232
1357
|
return 0;
|
|
1233
1358
|
}
|
|
1234
1359
|
function packageVersion(entry = Bun.main) {
|
|
1235
|
-
|
|
1360
|
+
let resolved = entry;
|
|
1361
|
+
try {
|
|
1362
|
+
resolved = realpathSync2(entry);
|
|
1363
|
+
} catch {}
|
|
1364
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1236
1365
|
try {
|
|
1237
|
-
const { version } = JSON.parse(
|
|
1366
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1238
1367
|
if (typeof version === "string")
|
|
1239
1368
|
return version;
|
|
1240
1369
|
} catch {}
|
|
@@ -1242,14 +1371,19 @@ function packageVersion(entry = Bun.main) {
|
|
|
1242
1371
|
return "0.0.0";
|
|
1243
1372
|
}
|
|
1244
1373
|
}
|
|
1245
|
-
async function runCli(cli, argv =
|
|
1374
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1246
1375
|
const version = cli.version ?? packageVersion();
|
|
1247
1376
|
if (argv[0] === COMPLETE)
|
|
1248
1377
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1378
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1379
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1380
|
+
const started = performance.now();
|
|
1249
1381
|
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 });
|
|
1382
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1383
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1250
1384
|
if (cli.usage !== false) {
|
|
1251
1385
|
try {
|
|
1252
|
-
recordUsage(usageEntry(cli.name,
|
|
1386
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1253
1387
|
} catch {}
|
|
1254
1388
|
}
|
|
1255
1389
|
return code;
|
|
@@ -1269,19 +1403,23 @@ function commandPath(scope, argv) {
|
|
|
1269
1403
|
}
|
|
1270
1404
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1271
1405
|
}
|
|
1272
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1406
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1273
1407
|
if (argv[0] === COMPLETE)
|
|
1274
1408
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1409
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1410
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1275
1411
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1276
1412
|
console.log(version ?? packageVersion());
|
|
1277
1413
|
return 0;
|
|
1278
1414
|
}
|
|
1279
1415
|
let code;
|
|
1416
|
+
const started = performance.now();
|
|
1280
1417
|
try {
|
|
1281
1418
|
code = await run(argv);
|
|
1282
1419
|
} catch (error) {
|
|
1283
1420
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1284
1421
|
}
|
|
1422
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1285
1423
|
if (usage !== false) {
|
|
1286
1424
|
try {
|
|
1287
1425
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1321,7 +1459,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1321
1459
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1322
1460
|
}
|
|
1323
1461
|
// ../kit/src/watch.ts
|
|
1324
|
-
import
|
|
1462
|
+
import process16 from "process";
|
|
1325
1463
|
import { format } from "util";
|
|
1326
1464
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1327
1465
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1343,7 +1481,7 @@ function withoutWatch(args) {
|
|
|
1343
1481
|
}
|
|
1344
1482
|
return rest;
|
|
1345
1483
|
}
|
|
1346
|
-
async function watching(value, step, stream =
|
|
1484
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1347
1485
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1348
1486
|
if (!takesControlCodes(stream))
|
|
1349
1487
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1351,12 +1489,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1351
1489
|
for (let round = 0;round < rounds; round++) {
|
|
1352
1490
|
const held = [];
|
|
1353
1491
|
const { log, info } = console;
|
|
1354
|
-
const write =
|
|
1492
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1355
1493
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1356
1494
|
`);
|
|
1357
1495
|
console.log = hold;
|
|
1358
1496
|
console.info = hold;
|
|
1359
|
-
|
|
1497
|
+
process16.stdout.write = (text) => {
|
|
1360
1498
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1361
1499
|
return true;
|
|
1362
1500
|
};
|
|
@@ -1365,7 +1503,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1365
1503
|
} finally {
|
|
1366
1504
|
console.log = log;
|
|
1367
1505
|
console.info = info;
|
|
1368
|
-
|
|
1506
|
+
process16.stdout.write = write;
|
|
1369
1507
|
}
|
|
1370
1508
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1371
1509
|
await sleep(interval);
|
|
@@ -1374,8 +1512,8 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1374
1512
|
}
|
|
1375
1513
|
// ../kit/src/workspace-root.ts
|
|
1376
1514
|
import { homedir as homedir4 } from "os";
|
|
1377
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1378
|
-
import
|
|
1515
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1516
|
+
import process17 from "process";
|
|
1379
1517
|
function expandHome(path, home) {
|
|
1380
1518
|
if (path === "~")
|
|
1381
1519
|
return home;
|
|
@@ -1385,20 +1523,20 @@ function configured(env, home) {
|
|
|
1385
1523
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1386
1524
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1387
1525
|
}
|
|
1388
|
-
function workspaceRoot({ given, env =
|
|
1526
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1389
1527
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1390
|
-
return
|
|
1528
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1391
1529
|
}
|
|
1392
1530
|
// src/repos.ts
|
|
1393
1531
|
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
1394
1532
|
import { basename as basename2, relative } from "path";
|
|
1395
|
-
import
|
|
1533
|
+
import process20 from "process";
|
|
1396
1534
|
|
|
1397
1535
|
// src/repos-scan.ts
|
|
1398
1536
|
import { existsSync as existsSync4 } from "fs";
|
|
1399
1537
|
import { readdir } from "fs/promises";
|
|
1400
1538
|
import { basename, join as join7 } from "path";
|
|
1401
|
-
import
|
|
1539
|
+
import process19 from "process";
|
|
1402
1540
|
var MAX_DEPTH = 3;
|
|
1403
1541
|
var CONCURRENCY = 8;
|
|
1404
1542
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1445,7 +1583,7 @@ async function findRepos(root, skip) {
|
|
|
1445
1583
|
}
|
|
1446
1584
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1447
1585
|
try {
|
|
1448
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1586
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process19.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1449
1587
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1450
1588
|
} catch {
|
|
1451
1589
|
return;
|
|
@@ -1522,7 +1660,7 @@ function firstLine(text) {
|
|
|
1522
1660
|
}
|
|
1523
1661
|
async function fastForward(path) {
|
|
1524
1662
|
try {
|
|
1525
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1663
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process19.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1526
1664
|
if (ran.timedOut)
|
|
1527
1665
|
return "timed out";
|
|
1528
1666
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1565,7 +1703,7 @@ function releasedCell(repo) {
|
|
|
1565
1703
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1566
1704
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1567
1705
|
}
|
|
1568
|
-
function syncCell(repo, stream =
|
|
1706
|
+
function syncCell(repo, stream = process20.stdout) {
|
|
1569
1707
|
const colors = paint(stream);
|
|
1570
1708
|
const ahead = repo.ahead ?? 0;
|
|
1571
1709
|
const behind = repo.behind ?? 0;
|
|
@@ -1576,7 +1714,7 @@ function syncCell(repo, stream = process18.stdout) {
|
|
|
1576
1714
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1577
1715
|
}
|
|
1578
1716
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1579
|
-
function branchCell(repo, stream =
|
|
1717
|
+
function branchCell(repo, stream = process20.stdout) {
|
|
1580
1718
|
const colors = paint(stream);
|
|
1581
1719
|
if (repo.unreadable)
|
|
1582
1720
|
return colors.red("? (unreadable)");
|
|
@@ -1585,8 +1723,8 @@ function branchCell(repo, stream = process18.stdout) {
|
|
|
1585
1723
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1586
1724
|
}
|
|
1587
1725
|
function row(repo, shown) {
|
|
1588
|
-
const colors = paint(
|
|
1589
|
-
const tint = role("path",
|
|
1726
|
+
const colors = paint(process20.stdout);
|
|
1727
|
+
const tint = role("path", process20.stdout);
|
|
1590
1728
|
const unreleased = releasedCell(repo);
|
|
1591
1729
|
return [
|
|
1592
1730
|
tint(shown),
|
|
@@ -1604,7 +1742,7 @@ async function repos(args) {
|
|
|
1604
1742
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1605
1743
|
if (!existsSync5(root) || !statSync2(root).isDirectory())
|
|
1606
1744
|
fail(`no folder ${root}`);
|
|
1607
|
-
const only = values.only
|
|
1745
|
+
const only = values.only;
|
|
1608
1746
|
const paths = await findRepos(root, await skipped());
|
|
1609
1747
|
const states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY), async (path) => inspect(path, values.fetch === true || values.pull === true));
|
|
1610
1748
|
const keeps = (repo) => {
|
|
@@ -1620,12 +1758,12 @@ async function repos(args) {
|
|
|
1620
1758
|
const blocker = pullBlocker(repo);
|
|
1621
1759
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1622
1760
|
if (blocker !== undefined) {
|
|
1623
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1761
|
+
log(marked("note", `${repo.name} skipped`, process20.stdout, blocker));
|
|
1624
1762
|
} else if (refused !== undefined) {
|
|
1625
1763
|
failedPulls++;
|
|
1626
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1764
|
+
log(marked("problem", `${repo.name} not pulled`, process20.stdout, refused));
|
|
1627
1765
|
} else {
|
|
1628
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1766
|
+
log(marked("ok", `${repo.name} pulled`, process20.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1629
1767
|
states[index] = await inspect(repo.path, false);
|
|
1630
1768
|
}
|
|
1631
1769
|
}
|
|
@@ -1640,7 +1778,7 @@ async function repos(args) {
|
|
|
1640
1778
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1641
1779
|
return failedPulls > 0 ? 1 : 0;
|
|
1642
1780
|
}
|
|
1643
|
-
const label = role("label",
|
|
1781
|
+
const label = role("label", process20.stdout);
|
|
1644
1782
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
1645
1783
|
if (kept.length === 0) {
|
|
1646
1784
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -1656,4 +1794,4 @@ async function repos(args) {
|
|
|
1656
1794
|
}
|
|
1657
1795
|
|
|
1658
1796
|
// src/repos-cli.ts
|
|
1659
|
-
|
|
1797
|
+
process21.exitCode = await runMain({ name: "repos", run: repos });
|