@kaynooo/cli-env 0.13.1 → 0.14.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/ev.js +725 -139
- package/dist/redact.js +254 -62
- package/package.json +3 -3
- package/src/commands/audit.ts +5 -3
- package/src/commands/compare.ts +7 -6
- package/src/commands/edit.ts +22 -18
- package/src/commands/pins.ts +5 -3
- package/src/commands/read.ts +13 -12
- package/src/commands/redact.ts +5 -2
- package/src/dotenv.ts +12 -1
- package/src/mask.ts +37 -6
package/dist/ev.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ev.ts
|
|
5
|
-
import
|
|
5
|
+
import process22 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -45,6 +45,9 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
45
45
|
return "terminal";
|
|
46
46
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
47
47
|
}
|
|
48
|
+
function isInteractive(streams = process2) {
|
|
49
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
// ../kit/src/style.ts
|
|
50
53
|
import process6 from "process";
|
|
@@ -374,6 +377,23 @@ var STATUS_WORDS = {
|
|
|
374
377
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
375
378
|
|
|
376
379
|
// ../kit/src/format.ts
|
|
380
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
381
|
+
function formatSeconds(total) {
|
|
382
|
+
let rest = Math.max(0, Math.round(total));
|
|
383
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
384
|
+
const amount = Math.floor(rest / size);
|
|
385
|
+
rest -= amount * size;
|
|
386
|
+
return `${amount}${unit}`;
|
|
387
|
+
});
|
|
388
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
389
|
+
if (first === -1)
|
|
390
|
+
return "0s";
|
|
391
|
+
const next = amounts[first + 1];
|
|
392
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
393
|
+
}
|
|
394
|
+
function formatDuration(ms) {
|
|
395
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
396
|
+
}
|
|
377
397
|
function upTo(text, separator) {
|
|
378
398
|
const end = text.indexOf(separator);
|
|
379
399
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -434,24 +454,20 @@ function printJson(value) {
|
|
|
434
454
|
|
|
435
455
|
// ../kit/src/help.ts
|
|
436
456
|
import process8 from "process";
|
|
437
|
-
var OPTIONAL =
|
|
457
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
438
458
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
439
459
|
var FULL_STOP = /\.$/;
|
|
440
460
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
441
461
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
442
462
|
}
|
|
443
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
444
|
-
return [usageLine(usage, colors),
|
|
463
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
464
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
445
465
|
`);
|
|
446
466
|
}
|
|
447
467
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
448
468
|
if (exits.length === 0)
|
|
449
469
|
return [];
|
|
450
|
-
|
|
451
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
452
|
-
}
|
|
453
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
454
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
470
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
455
471
|
}
|
|
456
472
|
function wantsHelpJson(env = process8.env) {
|
|
457
473
|
return env.KIT_HELP === "json";
|
|
@@ -477,29 +493,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
477
493
|
return [];
|
|
478
494
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
479
495
|
}
|
|
496
|
+
var MAX_INLINE_CHOICES = 24;
|
|
480
497
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
481
498
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
482
499
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
483
|
-
const
|
|
500
|
+
const choices = option.choices?.join("|");
|
|
501
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
502
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
484
503
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
485
504
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
486
|
-
|
|
505
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
506
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
487
507
|
});
|
|
488
508
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
489
509
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
490
510
|
}
|
|
491
511
|
|
|
492
512
|
// ../kit/src/text.ts
|
|
493
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
494
513
|
function distance(a, b) {
|
|
495
|
-
|
|
496
|
-
|
|
514
|
+
const left = [...a];
|
|
515
|
+
const right = [...b];
|
|
516
|
+
let before = [];
|
|
517
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
518
|
+
for (const [i, x] of left.entries()) {
|
|
497
519
|
const current = [i + 1];
|
|
498
|
-
for (const [j,
|
|
499
|
-
|
|
520
|
+
for (const [j, y] of right.entries()) {
|
|
521
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
522
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
523
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
524
|
+
current.push(cost);
|
|
525
|
+
}
|
|
526
|
+
before = previous;
|
|
500
527
|
previous = current;
|
|
501
528
|
}
|
|
502
|
-
return previous[
|
|
529
|
+
return previous[right.length] ?? 0;
|
|
503
530
|
}
|
|
504
531
|
function closest(name, names) {
|
|
505
532
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -567,7 +594,7 @@ class Completing {
|
|
|
567
594
|
}
|
|
568
595
|
var completion = { active: false };
|
|
569
596
|
var OUTPUT_OPTIONS = {
|
|
570
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
597
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
571
598
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
572
599
|
};
|
|
573
600
|
function applyOutput(color, plain, env = process10.env) {
|
|
@@ -739,21 +766,123 @@ function nearestOption(message, options, allowNegative) {
|
|
|
739
766
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
740
767
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
741
768
|
}
|
|
769
|
+
// ../kit/src/argv.ts
|
|
770
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
771
|
+
import { resolve as resolve3 } from "path";
|
|
772
|
+
import process11 from "process";
|
|
773
|
+
function commandLine() {
|
|
774
|
+
try {
|
|
775
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
776
|
+
} catch {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
function realPath(word) {
|
|
781
|
+
try {
|
|
782
|
+
return realpathSync(resolve3(word));
|
|
783
|
+
} catch {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
788
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
789
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
790
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
791
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
792
|
+
}
|
|
742
793
|
// ../kit/src/progress.ts
|
|
743
794
|
var ESC = String.fromCharCode(27);
|
|
744
795
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
745
796
|
var RESET_STYLE = `${ESC}[0m`;
|
|
746
797
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
747
798
|
// ../kit/src/cli.ts
|
|
748
|
-
import { readFileSync as
|
|
799
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
749
800
|
import { dirname as dirname3, join as join5 } from "path";
|
|
801
|
+
import process14 from "process";
|
|
802
|
+
|
|
803
|
+
// ../kit/src/completions.ts
|
|
804
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
805
|
+
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'
|
|
806
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
807
|
+
set -l current (commandline -ct)
|
|
808
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
809
|
+
if test "$line" = __files__
|
|
810
|
+
__fish_complete_path $current
|
|
811
|
+
else
|
|
812
|
+
echo $line
|
|
813
|
+
end
|
|
814
|
+
end
|
|
815
|
+
end`;
|
|
816
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
817
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
818
|
+
local -a lines
|
|
819
|
+
COMPREPLY=()
|
|
820
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
821
|
+
for line in "\${lines[@]}"; do
|
|
822
|
+
if [[ $line == __files__ ]]; then
|
|
823
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
824
|
+
else
|
|
825
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
826
|
+
fi
|
|
827
|
+
done
|
|
828
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
829
|
+
}`;
|
|
830
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
831
|
+
local line
|
|
832
|
+
local -a described plain
|
|
833
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
834
|
+
if [[ $line == __files__ ]]; then
|
|
835
|
+
_files
|
|
836
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
837
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
838
|
+
else
|
|
839
|
+
plain+=("$line")
|
|
840
|
+
fi
|
|
841
|
+
done
|
|
842
|
+
(( \${#described} )) && _describe -V value described
|
|
843
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
844
|
+
return 0
|
|
845
|
+
}`;
|
|
846
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
847
|
+
if (shell === "fish")
|
|
848
|
+
return `${header}
|
|
849
|
+
${FISH_FUNCTION}
|
|
850
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
851
|
+
`).join("")}`;
|
|
852
|
+
if (shell === "bash")
|
|
853
|
+
return `${header}
|
|
854
|
+
${BASH_FUNCTION}
|
|
855
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
856
|
+
`;
|
|
857
|
+
return `${header}
|
|
858
|
+
${ZSH_FUNCTION}
|
|
859
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
860
|
+
`;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// ../kit/src/notify.ts
|
|
750
864
|
import process12 from "process";
|
|
865
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
866
|
+
var CANCELLED = 130;
|
|
867
|
+
function base64(text) {
|
|
868
|
+
return Buffer.from(text).toString("base64");
|
|
869
|
+
}
|
|
870
|
+
function notification(title, body, env = process12.env) {
|
|
871
|
+
const id = `kit${process12.pid}`;
|
|
872
|
+
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\\`];
|
|
873
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
874
|
+
}
|
|
875
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
876
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
877
|
+
return;
|
|
878
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
879
|
+
}
|
|
751
880
|
|
|
752
881
|
// ../kit/src/usage.ts
|
|
753
882
|
import { appendFileSync, mkdirSync } from "fs";
|
|
754
883
|
import { homedir as homedir3 } from "os";
|
|
755
884
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
756
|
-
import
|
|
885
|
+
import process13 from "process";
|
|
757
886
|
|
|
758
887
|
// ../kit/src/logs.ts
|
|
759
888
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -767,14 +896,14 @@ var usageError;
|
|
|
767
896
|
function noteUsageError(message) {
|
|
768
897
|
usageError = message;
|
|
769
898
|
}
|
|
770
|
-
function stateHome(env =
|
|
899
|
+
function stateHome(env = process13.env) {
|
|
771
900
|
const dir = env.XDG_STATE_HOME;
|
|
772
901
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
773
902
|
}
|
|
774
|
-
function usagePath(env =
|
|
903
|
+
function usagePath(env = process13.env) {
|
|
775
904
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
776
905
|
}
|
|
777
|
-
function usageRecorded(env =
|
|
906
|
+
function usageRecorded(env = process13.env) {
|
|
778
907
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
779
908
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
780
909
|
}
|
|
@@ -788,7 +917,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
788
917
|
usageError = undefined;
|
|
789
918
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
790
919
|
}
|
|
791
|
-
function recordUsage(entry, env =
|
|
920
|
+
function recordUsage(entry, env = process13.env) {
|
|
792
921
|
if (!usageRecorded(env))
|
|
793
922
|
return;
|
|
794
923
|
try {
|
|
@@ -804,7 +933,11 @@ var LEVEL_OPTIONS = {
|
|
|
804
933
|
...OUTPUT_OPTIONS,
|
|
805
934
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
806
935
|
};
|
|
807
|
-
var TOP_OPTIONS = {
|
|
936
|
+
var TOP_OPTIONS = {
|
|
937
|
+
...LEVEL_OPTIONS,
|
|
938
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
939
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
940
|
+
};
|
|
808
941
|
async function commandRows(all, colors) {
|
|
809
942
|
const commands = shown(all);
|
|
810
943
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -865,7 +998,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
865
998
|
header(colors, summary),
|
|
866
999
|
"",
|
|
867
1000
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
868
|
-
...replacesRows(replaces, colors),
|
|
869
1001
|
"",
|
|
870
1002
|
...await commandRows(commands, colors),
|
|
871
1003
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -879,8 +1011,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
879
1011
|
`);
|
|
880
1012
|
}
|
|
881
1013
|
function printError(prefix, message, hint, cause) {
|
|
882
|
-
const colors = paint(
|
|
883
|
-
const styled = takesControlCodes(
|
|
1014
|
+
const colors = paint(process14.stderr);
|
|
1015
|
+
const styled = takesControlCodes(process14.stderr);
|
|
884
1016
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
885
1017
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
886
1018
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -923,11 +1055,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
923
1055
|
}
|
|
924
1056
|
}
|
|
925
1057
|
if (name === undefined && level.path.length > 1) {
|
|
926
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1058
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
927
1059
|
return 2;
|
|
928
1060
|
}
|
|
929
1061
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
930
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1062
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
931
1063
|
return 0;
|
|
932
1064
|
}
|
|
933
1065
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -983,24 +1115,24 @@ function candidateLine(candidate) {
|
|
|
983
1115
|
}
|
|
984
1116
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
985
1117
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
986
|
-
|
|
1118
|
+
const typed = [];
|
|
987
1119
|
let at = 0;
|
|
988
1120
|
while (at < before.length) {
|
|
989
1121
|
const word = before[at];
|
|
990
1122
|
if (word === "--") {
|
|
991
|
-
|
|
1123
|
+
typed.push(...before.slice(at + 1));
|
|
992
1124
|
break;
|
|
993
1125
|
}
|
|
994
1126
|
if (!word.startsWith("-"))
|
|
995
|
-
|
|
1127
|
+
typed.push(word);
|
|
996
1128
|
else if (takesValue(word))
|
|
997
1129
|
at++;
|
|
998
1130
|
at++;
|
|
999
1131
|
}
|
|
1000
1132
|
const last = positionals.at(-1);
|
|
1001
|
-
if (
|
|
1002
|
-
return positionals[
|
|
1003
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1133
|
+
if (typed.length < positionals.length)
|
|
1134
|
+
return { name: positionals[typed.length], typed };
|
|
1135
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1004
1136
|
}
|
|
1005
1137
|
async function leafCandidates(run, words) {
|
|
1006
1138
|
const completing = await completingOf(run);
|
|
@@ -1008,12 +1140,12 @@ async function leafCandidates(run, words) {
|
|
|
1008
1140
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1009
1141
|
const flag = words.at(-2);
|
|
1010
1142
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1143
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1011
1144
|
if (option?.type === "string") {
|
|
1012
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1145
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1013
1146
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1014
1147
|
}
|
|
1015
|
-
const
|
|
1016
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1148
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1017
1149
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1018
1150
|
}
|
|
1019
1151
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1038,15 +1170,32 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1038
1170
|
}
|
|
1039
1171
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1040
1172
|
}
|
|
1173
|
+
var COMPLETIONS = "--completions";
|
|
1174
|
+
function flagValue([flag = "", ...rest]) {
|
|
1175
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1176
|
+
}
|
|
1177
|
+
function printCompletionScript(name, args) {
|
|
1178
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1179
|
+
if (shell === undefined || args.length !== 1) {
|
|
1180
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1181
|
+
return 2;
|
|
1182
|
+
}
|
|
1183
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1184
|
+
return 0;
|
|
1185
|
+
}
|
|
1041
1186
|
async function printCandidates(found) {
|
|
1042
1187
|
for (const line of await found)
|
|
1043
1188
|
console.log(line);
|
|
1044
1189
|
return 0;
|
|
1045
1190
|
}
|
|
1046
1191
|
function packageVersion(entry = Bun.main) {
|
|
1047
|
-
|
|
1192
|
+
let resolved = entry;
|
|
1193
|
+
try {
|
|
1194
|
+
resolved = realpathSync2(entry);
|
|
1195
|
+
} catch {}
|
|
1196
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1048
1197
|
try {
|
|
1049
|
-
const { version } = JSON.parse(
|
|
1198
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1050
1199
|
if (typeof version === "string")
|
|
1051
1200
|
return version;
|
|
1052
1201
|
} catch {}
|
|
@@ -1054,14 +1203,19 @@ function packageVersion(entry = Bun.main) {
|
|
|
1054
1203
|
return "0.0.0";
|
|
1055
1204
|
}
|
|
1056
1205
|
}
|
|
1057
|
-
async function runCli(cli, argv =
|
|
1206
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1058
1207
|
const version = cli.version ?? packageVersion();
|
|
1059
1208
|
if (argv[0] === COMPLETE)
|
|
1060
1209
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1210
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1211
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1212
|
+
const started = performance.now();
|
|
1061
1213
|
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 });
|
|
1214
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1215
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1062
1216
|
if (cli.usage !== false) {
|
|
1063
1217
|
try {
|
|
1064
|
-
recordUsage(usageEntry(cli.name,
|
|
1218
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1065
1219
|
} catch {}
|
|
1066
1220
|
}
|
|
1067
1221
|
return code;
|
|
@@ -1081,19 +1235,23 @@ function commandPath(scope, argv) {
|
|
|
1081
1235
|
}
|
|
1082
1236
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1083
1237
|
}
|
|
1084
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1238
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1085
1239
|
if (argv[0] === COMPLETE)
|
|
1086
1240
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1241
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1242
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1087
1243
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1088
1244
|
console.log(version ?? packageVersion());
|
|
1089
1245
|
return 0;
|
|
1090
1246
|
}
|
|
1091
1247
|
let code;
|
|
1248
|
+
const started = performance.now();
|
|
1092
1249
|
try {
|
|
1093
1250
|
code = await run(argv);
|
|
1094
1251
|
} catch (error) {
|
|
1095
1252
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1096
1253
|
}
|
|
1254
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1097
1255
|
if (usage !== false) {
|
|
1098
1256
|
try {
|
|
1099
1257
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1111,12 +1269,18 @@ async function compose(args, { flags = [], ...options } = {}) {
|
|
|
1111
1269
|
return captureOutput(["docker", "compose", ...flags, ...args], options);
|
|
1112
1270
|
}
|
|
1113
1271
|
// ../kit/src/folders.ts
|
|
1272
|
+
import { homedir as homedir4 } from "os";
|
|
1273
|
+
import { join as join6 } from "path";
|
|
1274
|
+
import process15 from "process";
|
|
1114
1275
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1115
1276
|
function ignoredFolders(extra = [], where = {}) {
|
|
1116
1277
|
const configured = readUserConfig("config", where).ignore;
|
|
1117
1278
|
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1118
1279
|
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1119
1280
|
}
|
|
1281
|
+
function cacheFolder({ home = homedir4(), env = process15.env } = {}) {
|
|
1282
|
+
return env.XDG_CACHE_HOME ?? join6(home, ".cache");
|
|
1283
|
+
}
|
|
1120
1284
|
// ../kit/src/secrets.ts
|
|
1121
1285
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1122
1286
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1130,8 +1294,8 @@ var SESSION_FILES = new Glob("*.json");
|
|
|
1130
1294
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1131
1295
|
// src/commands/audit.ts
|
|
1132
1296
|
import { stat as stat4 } from "fs/promises";
|
|
1133
|
-
import { relative, resolve as
|
|
1134
|
-
import
|
|
1297
|
+
import { relative, resolve as resolve4 } from "path";
|
|
1298
|
+
import process17 from "process";
|
|
1135
1299
|
|
|
1136
1300
|
// ../kit/src/shell.ts
|
|
1137
1301
|
var SEPARATORS = new Set([`
|
|
@@ -1182,12 +1346,12 @@ function shellQuote(word) {
|
|
|
1182
1346
|
|
|
1183
1347
|
// src/audit.ts
|
|
1184
1348
|
import { readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
1185
|
-
import { dirname as dirname5, join as
|
|
1349
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1186
1350
|
var {$ } = globalThis.Bun;
|
|
1187
1351
|
|
|
1188
1352
|
// src/files.ts
|
|
1189
1353
|
import { chmod, chown, readdir, realpath, rename, rm, stat, writeFile } from "fs/promises";
|
|
1190
|
-
import { basename, dirname as dirname4, join as
|
|
1354
|
+
import { basename, dirname as dirname4, join as join7 } from "path";
|
|
1191
1355
|
|
|
1192
1356
|
// src/dotenv.ts
|
|
1193
1357
|
var ASSIGNMENT = /^\s*(?:export\s+)?([A-Z_][\w.-]*)\s*=(.*)$/i;
|
|
@@ -1245,7 +1409,8 @@ function parseDotenv(text) {
|
|
|
1245
1409
|
let body = start.slice(1);
|
|
1246
1410
|
let raw = line;
|
|
1247
1411
|
let end = closingQuote(body, quote);
|
|
1248
|
-
|
|
1412
|
+
const first = index;
|
|
1413
|
+
while (end === -1 && index + 1 < physical.length && !ASSIGNMENT.test(physical[index + 1] ?? "")) {
|
|
1249
1414
|
index++;
|
|
1250
1415
|
body += `
|
|
1251
1416
|
${(physical[index] ?? "").replace(CARRIAGE_RETURN, "")}`;
|
|
@@ -1253,6 +1418,11 @@ ${(physical[index] ?? "").replace(CARRIAGE_RETURN, "")}`;
|
|
|
1253
1418
|
${physical[index] ?? ""}`;
|
|
1254
1419
|
end = closingQuote(body, quote);
|
|
1255
1420
|
}
|
|
1421
|
+
if (end === -1 && index + 1 < physical.length) {
|
|
1422
|
+
index = first;
|
|
1423
|
+
lines.push({ raw: line, key, value: unescapeDollar(start.replace(INLINE_COMMENT, "").trim()), unterminated: true });
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1256
1426
|
const inner = end === -1 ? body : body.slice(0, end);
|
|
1257
1427
|
lines.push({ raw, key, value: quote === '"' ? unescapeDouble(inner) : unescapeDollar(inner) });
|
|
1258
1428
|
}
|
|
@@ -1318,9 +1488,30 @@ var ESCAPE2 = /[.*+?^${}()|[\]\\]/g;
|
|
|
1318
1488
|
function isPlaceholder(value) {
|
|
1319
1489
|
return PLACEHOLDER.test(value) || PLAIN_VALUE.test(value);
|
|
1320
1490
|
}
|
|
1491
|
+
var STRONG_NAME = "password|passwd|secret|api[_-]?key|access[_-]?key|private[_-]?key|account[_-]?key|shared[_-]?access[_-]?key";
|
|
1492
|
+
var WEAK_NAME = "token|credentials?|auth";
|
|
1493
|
+
var PLAIN_WORD = /^[a-z]+$/i;
|
|
1494
|
+
var AFTER_COLON = /:\s*$/;
|
|
1495
|
+
var DIGIT = /\d/;
|
|
1496
|
+
var KEY_VALUE_GAP = "\\s*[:=]\\s*";
|
|
1497
|
+
function isProse(value, before) {
|
|
1498
|
+
return isPlaceholder(value) || AFTER_COLON.test(before) && PLAIN_WORD.test(value);
|
|
1499
|
+
}
|
|
1500
|
+
function isWeak(value, before) {
|
|
1501
|
+
return isProse(value, before) || !(DIGIT.test(value) || value.length >= 16);
|
|
1502
|
+
}
|
|
1503
|
+
function keyed(names, value) {
|
|
1504
|
+
return new RegExp(`(?<![\\w-])["']?(?:[\\w-]{0,30}[_-])?(?:${names})(?:[_-][\\w-]{0,30})?["']?${KEY_VALUE_GAP}${value}`, "dgi");
|
|
1505
|
+
}
|
|
1321
1506
|
var TOKEN_FORMATS = [
|
|
1322
1507
|
{ kind: "GitHub token", pattern: /\b(?:gh[pousr]_|github_pat_)\w{20,}/dg },
|
|
1323
|
-
{ kind: "GitLab token", pattern: /\
|
|
1508
|
+
{ kind: "GitLab token", pattern: /\bgl(?:pat|rt|dt|ptt)-[\w-]{20,}/dg },
|
|
1509
|
+
{ kind: "Hugging Face token", pattern: /\bhf_[A-Za-z]{30,}/dg },
|
|
1510
|
+
{ kind: "webhook secret", pattern: /\bwhsec_\w{20,}/dg },
|
|
1511
|
+
{ kind: "DigitalOcean token", pattern: /\bdop_v1_\w{20,}/dg },
|
|
1512
|
+
{ kind: "Shopify token", pattern: /\bshp(?:at|ca|pa|ss)_\w{20,}/dg },
|
|
1513
|
+
{ kind: "password", pattern: /\bmysql(?:dump|admin)?\s+(?:\S+\s+)*?-p([^\s"'|;&-]\S{3,})/dg },
|
|
1514
|
+
{ kind: "password", pattern: /\bsshpass\s+(?:-[a-oq-z]\s+)*-p\s*([^\s"'|;&]{4,})/dg },
|
|
1324
1515
|
{ kind: "API key", pattern: /\bsk-[\w-]{20,}/dg },
|
|
1325
1516
|
{ kind: "Slack token", pattern: /\bx(?:ox[abprs]|app)-[\w-]{10,}/dg },
|
|
1326
1517
|
{ kind: "JWT", pattern: /\beyJ[\w-]+\.[\w-]+\.[\w-]+/dg },
|
|
@@ -1331,8 +1522,10 @@ var TOKEN_FORMATS = [
|
|
|
1331
1522
|
{ kind: "SendGrid key", pattern: /\bSG\.[\w-]{16,}\.[\w-]{16,}/dg },
|
|
1332
1523
|
{ kind: "Authorization header", pattern: /\bAuthorization["']?\s*[:=]\s*["']?(?:Bearer|Basic|Token|Digest)\s+([^\s"',;]{8,})/dgi, skip: isPlaceholder },
|
|
1333
1524
|
{ kind: "Bearer token", pattern: /\bBearer\s+((?=[\w.~+/=-]*\d)[\w.~+/=-]{20,})/dg },
|
|
1334
|
-
{ kind: "password", pattern:
|
|
1335
|
-
{ kind: "password", pattern:
|
|
1525
|
+
{ kind: "password", pattern: keyed(STRONG_NAME, `([^\\s"'&;,]{4,})`), skip: isProse },
|
|
1526
|
+
{ kind: "password", pattern: keyed(WEAK_NAME, `([^\\s"'&;,]{4,})`), skip: isWeak },
|
|
1527
|
+
{ kind: "password", pattern: keyed(STRONG_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isPlaceholder },
|
|
1528
|
+
{ kind: "password", pattern: keyed(WEAK_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isWeak }
|
|
1336
1529
|
];
|
|
1337
1530
|
var PEM_BEGIN = /-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
1338
1531
|
var PEM_END = /-----END [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
@@ -1437,7 +1630,7 @@ function findSecrets(line, known) {
|
|
|
1437
1630
|
if (start === undefined || end === undefined)
|
|
1438
1631
|
continue;
|
|
1439
1632
|
const value = line.slice(start, end);
|
|
1440
|
-
if (!skip?.(value))
|
|
1633
|
+
if (!skip?.(value, line.slice(0, start)))
|
|
1441
1634
|
found.push({ start, end, kind, mask: hint(value) });
|
|
1442
1635
|
}
|
|
1443
1636
|
}
|
|
@@ -1499,7 +1692,7 @@ async function envFiles(folder = process.cwd()) {
|
|
|
1499
1692
|
const found = await readdir(folder, { withFileTypes: true });
|
|
1500
1693
|
const names = [];
|
|
1501
1694
|
for (const entry of found) {
|
|
1502
|
-
if (ENV_FILE.test(entry.name) && await isFileEntry(entry,
|
|
1695
|
+
if (ENV_FILE.test(entry.name) && await isFileEntry(entry, join7(folder, entry.name)))
|
|
1503
1696
|
names.push(entry.name);
|
|
1504
1697
|
}
|
|
1505
1698
|
return names.sort();
|
|
@@ -1523,7 +1716,7 @@ async function writeAtomic(path, text) {
|
|
|
1523
1716
|
if (error.code !== "ENOENT")
|
|
1524
1717
|
throw error;
|
|
1525
1718
|
}
|
|
1526
|
-
const temp =
|
|
1719
|
+
const temp = join7(dirname4(target), `.${basename(target)}.${process.pid}.${crypto.randomUUID()}.tmp`);
|
|
1527
1720
|
try {
|
|
1528
1721
|
await writeFile(temp, text, { mode: 384, flag: "wx" });
|
|
1529
1722
|
if (owner !== undefined)
|
|
@@ -1579,7 +1772,7 @@ async function acquire(path) {
|
|
|
1579
1772
|
try {
|
|
1580
1773
|
real = await realpath(path);
|
|
1581
1774
|
} catch {}
|
|
1582
|
-
const lock =
|
|
1775
|
+
const lock = join7(dirname4(real), `.${basename(real)}.lock`);
|
|
1583
1776
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
1584
1777
|
while (true) {
|
|
1585
1778
|
try {
|
|
@@ -1614,7 +1807,7 @@ async function envFilesBelow(folder, depth = 0) {
|
|
|
1614
1807
|
return found;
|
|
1615
1808
|
}
|
|
1616
1809
|
for (const entry of children) {
|
|
1617
|
-
const path =
|
|
1810
|
+
const path = join7(folder, entry.name);
|
|
1618
1811
|
if (entry.isDirectory() && depth < KNOWN_DEPTH && !SKIPPED.has(entry.name))
|
|
1619
1812
|
found.push(...await envFilesBelow(path, depth + 1));
|
|
1620
1813
|
else if (ENV_FILE.test(entry.name) && await isFileEntry(entry, path))
|
|
@@ -1705,7 +1898,7 @@ async function* candidates2(root, unread, depth = 0) {
|
|
|
1705
1898
|
return;
|
|
1706
1899
|
}
|
|
1707
1900
|
for (const entry of found) {
|
|
1708
|
-
const path =
|
|
1901
|
+
const path = join8(root, entry.name);
|
|
1709
1902
|
if (entry.isDirectory() && depth < MAX_DEPTH && !SKIPPED.has(entry.name))
|
|
1710
1903
|
yield* candidates2(path, unread, depth + 1);
|
|
1711
1904
|
else if (!TEMPLATE.test(entry.name) && (ENV_FILE.test(entry.name) || COMPOSE_FILE.test(entry.name)) && await isFileEntry(entry, path))
|
|
@@ -1737,7 +1930,7 @@ async function audit(roots) {
|
|
|
1737
1930
|
|
|
1738
1931
|
// src/fix.ts
|
|
1739
1932
|
import { chmod as chmod2, chown as chown2, lstat, rm as rm2, stat as stat3 } from "fs/promises";
|
|
1740
|
-
import { dirname as dirname6, join as
|
|
1933
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1741
1934
|
var MAP_ENTRY = /^(\s*)(["']?)([A-Z0-9_]+)\2(\s*:)(.*)$/;
|
|
1742
1935
|
var LIST_ENTRY = /^(\s*-[ \t]*)(["']?)([A-Z0-9_]+)=(.*)$/;
|
|
1743
1936
|
var TRAILING = /^\s*(?:#.*)?$/;
|
|
@@ -1830,7 +2023,7 @@ async function shutOthersOut(path, group = false) {
|
|
|
1830
2023
|
}
|
|
1831
2024
|
}
|
|
1832
2025
|
async function fixCompose(path, group = false) {
|
|
1833
|
-
const env =
|
|
2026
|
+
const env = join9(dirname6(path), ".env");
|
|
1834
2027
|
const compose = await Bun.file(path).text();
|
|
1835
2028
|
const envBefore = await Bun.file(env).exists() ? await Bun.file(env).text() : undefined;
|
|
1836
2029
|
const dotenv = parseDotenv(envBefore ?? "");
|
|
@@ -1927,8 +2120,8 @@ var usage2 = `ev audit [dir...] [--fix]
|
|
|
1927
2120
|
|
|
1928
2121
|
Lists the .env files any account on the machine can read or git tracks, and the compose files any account can read that write a secret out (a secret-named value or a URL password) instead of reading it from a .env, never printing a value.
|
|
1929
2122
|
Looks under each folder (the current one by default) down to 5 levels, skipping node_modules, vendor and .git, and leaves .example, .sample, .template and .dist files out. A folder it cannot read is named on stderr.
|
|
1930
|
-
With --fix, moves each secret a listed compose file writes out into the .env beside it as \${KEY}, puts it back when \`docker compose config\` resolves differently after, and shuts other accounts out of both files and of every listed .env; a key the .env already sets to another value stays put
|
|
1931
|
-
|
|
2123
|
+
With --fix, moves each secret a listed compose file writes out into the .env beside it as \${KEY}, puts it back when \`docker compose config\` resolves differently after, and shuts other accounts out of both files and of every listed .env; a key the .env already sets to another value stays put.`;
|
|
2124
|
+
var EXITS = [[0, "it finds none (with --fix, when none is left)"], [1, "it finds one"], [2, "a usage error"]];
|
|
1932
2125
|
var options = {
|
|
1933
2126
|
json: jsonOption("the findings and the folders it could not read"),
|
|
1934
2127
|
fix: { type: "boolean", description: "move inline compose secrets into a .env and shut other accounts out" }
|
|
@@ -1948,12 +2141,12 @@ async function isFolder(path) {
|
|
|
1948
2141
|
}
|
|
1949
2142
|
}
|
|
1950
2143
|
function shown2(path) {
|
|
1951
|
-
return path.startsWith(`${
|
|
2144
|
+
return path.startsWith(`${process17.cwd()}/`) ? relative(process17.cwd(), path) : path;
|
|
1952
2145
|
}
|
|
1953
2146
|
async function fixAll(exposed, json) {
|
|
1954
2147
|
const fixed = [];
|
|
1955
2148
|
let left = false;
|
|
1956
|
-
const tint = role("path",
|
|
2149
|
+
const tint = role("path", process17.stdout);
|
|
1957
2150
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
1958
2151
|
const fix = secrets === undefined ? undefined : await fixCompose(path, group === true);
|
|
1959
2152
|
const open = fix?.open ?? (readable && !await shutOthersOut(path, group === true) ? [path] : []);
|
|
@@ -1977,8 +2170,8 @@ async function fixAll(exposed, json) {
|
|
|
1977
2170
|
return { fixed, left };
|
|
1978
2171
|
}
|
|
1979
2172
|
async function audit2(args) {
|
|
1980
|
-
const parsed = parse(args, usage2, options);
|
|
1981
|
-
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) =>
|
|
2173
|
+
const parsed = parse(args, usage2, options, { exits: EXITS });
|
|
2174
|
+
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) => resolve4(dir));
|
|
1982
2175
|
for (const dir of roots) {
|
|
1983
2176
|
if (!await isFolder(dir))
|
|
1984
2177
|
fail(`${dir} is not a folder`);
|
|
@@ -2005,8 +2198,8 @@ async function audit2(args) {
|
|
|
2005
2198
|
console.log("no exposed .env file nor compose file writing a secret out");
|
|
2006
2199
|
return 0;
|
|
2007
2200
|
}
|
|
2008
|
-
const uid =
|
|
2009
|
-
const tint = role("path",
|
|
2201
|
+
const uid = process17.getuid?.();
|
|
2202
|
+
const tint = role("path", process17.stdout);
|
|
2010
2203
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
2011
2204
|
const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
|
|
2012
2205
|
const problems = [
|
|
@@ -2022,27 +2215,25 @@ async function audit2(args) {
|
|
|
2022
2215
|
}
|
|
2023
2216
|
|
|
2024
2217
|
// src/commands/compare.ts
|
|
2025
|
-
import
|
|
2218
|
+
import process18 from "process";
|
|
2026
2219
|
var diffUsage = `ev diff <a> <b>
|
|
2027
2220
|
|
|
2028
2221
|
Names the keys set in one file and not the other, never their values.
|
|
2029
2222
|
|
|
2030
|
-
--json prints {a, b, onlyA, onlyB}
|
|
2031
|
-
|
|
2032
|
-
Exits 0 when both set the same keys, 1 when they differ, 2 on a usage error.`;
|
|
2223
|
+
--json prints {a, b, onlyA, onlyB}.`;
|
|
2224
|
+
var DIFF_EXITS = [[0, "both set the same keys"], [1, "they differ"], [2, "a usage error"]];
|
|
2033
2225
|
var missingUsage = `ev missing [file]
|
|
2034
2226
|
|
|
2035
2227
|
Names the keys the reference file sets that the file (.env by default) does not.
|
|
2036
2228
|
|
|
2037
|
-
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing
|
|
2038
|
-
|
|
2039
|
-
Exits 0 when none is missing, 1 when some are, 2 on a usage error.`;
|
|
2229
|
+
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing.`;
|
|
2230
|
+
var MISSING_EXITS = [[0, "none is missing"], [1, "some are"], [2, "a usage error"]];
|
|
2040
2231
|
var jsonFlag = { json: jsonOption() };
|
|
2041
2232
|
async function keys(path) {
|
|
2042
2233
|
return new Set(entries(await readEnv(path)).keys());
|
|
2043
2234
|
}
|
|
2044
2235
|
async function diff(args) {
|
|
2045
|
-
const parsed = parse(args, diffUsage, jsonFlag);
|
|
2236
|
+
const parsed = parse(args, diffUsage, jsonFlag, { exits: DIFF_EXITS });
|
|
2046
2237
|
const [a, b] = parsed.positionals;
|
|
2047
2238
|
if (a === undefined || b === undefined)
|
|
2048
2239
|
fail(`needs two files
|
|
@@ -2056,8 +2247,8 @@ ${diffUsage}`);
|
|
|
2056
2247
|
printJson({ a, b, onlyA, onlyB });
|
|
2057
2248
|
return onlyA.length + onlyB.length === 0 ? 0 : 1;
|
|
2058
2249
|
}
|
|
2059
|
-
const path = role("path",
|
|
2060
|
-
const value = role("value",
|
|
2250
|
+
const path = role("path", process18.stdout);
|
|
2251
|
+
const value = role("value", process18.stdout);
|
|
2061
2252
|
const lines = [...onlyA.map((key) => `only in ${path(a)}: ${value(key)}`), ...onlyB.map((key) => `only in ${path(b)}: ${value(key)}`)];
|
|
2062
2253
|
if (lines.length === 0)
|
|
2063
2254
|
return 0;
|
|
@@ -2066,7 +2257,7 @@ ${diffUsage}`);
|
|
|
2066
2257
|
return 1;
|
|
2067
2258
|
}
|
|
2068
2259
|
async function missing(args) {
|
|
2069
|
-
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag });
|
|
2260
|
+
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag }, { exits: MISSING_EXITS });
|
|
2070
2261
|
const [file = ".env"] = parsed.positionals;
|
|
2071
2262
|
const against = parsed.values.against ?? ".env.example";
|
|
2072
2263
|
const have = await keys(file);
|
|
@@ -2078,13 +2269,417 @@ async function missing(args) {
|
|
|
2078
2269
|
}
|
|
2079
2270
|
if (absent.length === 0)
|
|
2080
2271
|
return 0;
|
|
2081
|
-
const path = role("path",
|
|
2082
|
-
const value = role("value",
|
|
2272
|
+
const path = role("path", process18.stdout);
|
|
2273
|
+
const value = role("value", process18.stdout);
|
|
2083
2274
|
console.log(absent.map((key) => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join(`
|
|
2084
2275
|
`));
|
|
2085
2276
|
return 1;
|
|
2086
2277
|
}
|
|
2087
2278
|
|
|
2279
|
+
// ../kit/src/prompt.ts
|
|
2280
|
+
import process20 from "process";
|
|
2281
|
+
|
|
2282
|
+
// ../kit/src/answers.ts
|
|
2283
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
2284
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
2285
|
+
var KEPT = 50;
|
|
2286
|
+
function answersFile() {
|
|
2287
|
+
return join10(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
2288
|
+
}
|
|
2289
|
+
function stored() {
|
|
2290
|
+
try {
|
|
2291
|
+
const parsed = JSON.parse(readFileSync5(answersFile(), "utf-8"));
|
|
2292
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
2293
|
+
return {};
|
|
2294
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
2295
|
+
} catch {
|
|
2296
|
+
return {};
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
function earlierAnswers(key) {
|
|
2300
|
+
return stored()[key] ?? [];
|
|
2301
|
+
}
|
|
2302
|
+
function rememberAnswer(key, answer) {
|
|
2303
|
+
const all = stored();
|
|
2304
|
+
const file = answersFile();
|
|
2305
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
2306
|
+
try {
|
|
2307
|
+
mkdirSync2(dirname7(file), { recursive: true });
|
|
2308
|
+
writeFileSync(file, JSON.stringify(all));
|
|
2309
|
+
} catch {}
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// ../kit/src/job.ts
|
|
2313
|
+
import process19 from "process";
|
|
2314
|
+
function stopJob() {
|
|
2315
|
+
process19.kill(0, "SIGTSTP");
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
// ../kit/src/picker/line.ts
|
|
2319
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2320
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2321
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2322
|
+
function isEditKey(key) {
|
|
2323
|
+
return EDIT_KEYS.has(key);
|
|
2324
|
+
}
|
|
2325
|
+
function endsKills(key) {
|
|
2326
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
2327
|
+
}
|
|
2328
|
+
var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
2329
|
+
var SPACE = /\s/;
|
|
2330
|
+
function isWord(char) {
|
|
2331
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
2332
|
+
}
|
|
2333
|
+
function wordStart(chars, from) {
|
|
2334
|
+
let at = from;
|
|
2335
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
2336
|
+
at--;
|
|
2337
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
2338
|
+
at--;
|
|
2339
|
+
return at;
|
|
2340
|
+
}
|
|
2341
|
+
function wordEnd(chars, from) {
|
|
2342
|
+
let at = from;
|
|
2343
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
2344
|
+
at++;
|
|
2345
|
+
while (at < chars.length && isWord(chars[at]))
|
|
2346
|
+
at++;
|
|
2347
|
+
return at;
|
|
2348
|
+
}
|
|
2349
|
+
function spacedStart(chars, from) {
|
|
2350
|
+
let at = from;
|
|
2351
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
2352
|
+
at--;
|
|
2353
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
2354
|
+
at--;
|
|
2355
|
+
return at;
|
|
2356
|
+
}
|
|
2357
|
+
function cut(chars, from, to) {
|
|
2358
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
2359
|
+
}
|
|
2360
|
+
function insert(chars, at, text) {
|
|
2361
|
+
const typed = [...text];
|
|
2362
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
2363
|
+
}
|
|
2364
|
+
function editLine(line, key) {
|
|
2365
|
+
const { killed = "", chained = false } = line;
|
|
2366
|
+
const chars = [...line.text];
|
|
2367
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
2368
|
+
const edited = edit(chars, at, key, killed);
|
|
2369
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
2370
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
2371
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
2372
|
+
if (taken === "")
|
|
2373
|
+
return { ...edited, killed, chained };
|
|
2374
|
+
if (!chained)
|
|
2375
|
+
return { ...edited, killed: taken, chained: true };
|
|
2376
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
2377
|
+
}
|
|
2378
|
+
function edit(chars, at, key, killed) {
|
|
2379
|
+
const text = chars.join("");
|
|
2380
|
+
if (typeof key === "object")
|
|
2381
|
+
return insert(chars, at, key.text);
|
|
2382
|
+
switch (key) {
|
|
2383
|
+
case "left":
|
|
2384
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
2385
|
+
case "right":
|
|
2386
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
2387
|
+
case "wordleft":
|
|
2388
|
+
return { text, caret: wordStart(chars, at) };
|
|
2389
|
+
case "wordright":
|
|
2390
|
+
return { text, caret: wordEnd(chars, at) };
|
|
2391
|
+
case "linestart":
|
|
2392
|
+
return { text, caret: 0 };
|
|
2393
|
+
case "lineend":
|
|
2394
|
+
return { text, caret: chars.length };
|
|
2395
|
+
case "erase":
|
|
2396
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
2397
|
+
case "delete":
|
|
2398
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
2399
|
+
case "word":
|
|
2400
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
2401
|
+
case "killword":
|
|
2402
|
+
return cut(chars, wordStart(chars, at), at);
|
|
2403
|
+
case "killnext":
|
|
2404
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
2405
|
+
case "clear":
|
|
2406
|
+
return cut(chars, 0, at);
|
|
2407
|
+
case "killend":
|
|
2408
|
+
return cut(chars, at, chars.length);
|
|
2409
|
+
case "yank":
|
|
2410
|
+
return insert(chars, at, killed);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
function visible({ text, caret }, room) {
|
|
2414
|
+
const chars = [...text];
|
|
2415
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
2416
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
2417
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
2418
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
2419
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
2420
|
+
let start = at;
|
|
2421
|
+
let end = at + 1;
|
|
2422
|
+
while (start > 0 && fits(start - 1, end))
|
|
2423
|
+
start--;
|
|
2424
|
+
while (end < cells.length && fits(start, end + 1))
|
|
2425
|
+
end++;
|
|
2426
|
+
const left = start > 0 ? "\u2026" : "";
|
|
2427
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
2428
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
// ../kit/src/picker/score.ts
|
|
2432
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
2433
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
2434
|
+
|
|
2435
|
+
// ../kit/src/picker/state.ts
|
|
2436
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2437
|
+
var PASTE_START = "\x1B[200~";
|
|
2438
|
+
var PASTE_END = "\x1B[201~";
|
|
2439
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2440
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
2441
|
+
var WHEEL_LINES = 3;
|
|
2442
|
+
var KEYS = {
|
|
2443
|
+
"\x1B[A": "up",
|
|
2444
|
+
"\x1BOA": "up",
|
|
2445
|
+
"\x10": "up",
|
|
2446
|
+
"\x1B[B": "down",
|
|
2447
|
+
"\x1BOB": "down",
|
|
2448
|
+
"\x0E": "down",
|
|
2449
|
+
"\x1B[5~": "pageup",
|
|
2450
|
+
"\x1B[6~": "pagedown",
|
|
2451
|
+
"\x1B[H": "home",
|
|
2452
|
+
"\x1B[1~": "home",
|
|
2453
|
+
"\x1BOH": "home",
|
|
2454
|
+
"\x1B[F": "end",
|
|
2455
|
+
"\x1B[4~": "end",
|
|
2456
|
+
"\x1BOF": "end",
|
|
2457
|
+
"\r": "enter",
|
|
2458
|
+
"\n": "enter",
|
|
2459
|
+
"\x03": "cancel",
|
|
2460
|
+
"\x1B": "cancel",
|
|
2461
|
+
"\x1B[D": "left",
|
|
2462
|
+
"\x1BOD": "left",
|
|
2463
|
+
"\x1B[C": "right",
|
|
2464
|
+
"\x1BOC": "right",
|
|
2465
|
+
"\x1B[1;5D": "wordleft",
|
|
2466
|
+
"\x1B[1;3D": "wordleft",
|
|
2467
|
+
"\x1Bb": "wordleft",
|
|
2468
|
+
"\x1B[1;5C": "wordright",
|
|
2469
|
+
"\x1B[1;3C": "wordright",
|
|
2470
|
+
"\x1Bf": "wordright",
|
|
2471
|
+
"\x01": "linestart",
|
|
2472
|
+
"\x05": "lineend",
|
|
2473
|
+
"\x7F": "erase",
|
|
2474
|
+
"\x1B[3~": "delete",
|
|
2475
|
+
"\b": "killword",
|
|
2476
|
+
"\x1B\x7F": "killword",
|
|
2477
|
+
"\x1B[3;5~": "killnext",
|
|
2478
|
+
"\x1Bd": "killnext",
|
|
2479
|
+
"\x15": "clear",
|
|
2480
|
+
"\v": "killend",
|
|
2481
|
+
"\x17": "word",
|
|
2482
|
+
"\x19": "yank",
|
|
2483
|
+
"\x1A": "suspend",
|
|
2484
|
+
"\t": "tab",
|
|
2485
|
+
"\x1F": "help",
|
|
2486
|
+
"\x1BOP": "help",
|
|
2487
|
+
"\x1B[11~": "help"
|
|
2488
|
+
};
|
|
2489
|
+
function repeat(value, count) {
|
|
2490
|
+
return Array.from({ length: count }).fill(value);
|
|
2491
|
+
}
|
|
2492
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2493
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2494
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2495
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2496
|
+
if (wheel !== undefined)
|
|
2497
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
2498
|
+
const named = codes.get(sequence);
|
|
2499
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2500
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2501
|
+
paste.active = sequence === PASTE_START;
|
|
2502
|
+
return [];
|
|
2503
|
+
}
|
|
2504
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
2505
|
+
`))
|
|
2506
|
+
return [];
|
|
2507
|
+
if (key !== undefined)
|
|
2508
|
+
return [key];
|
|
2509
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
// ../kit/src/redraw.ts
|
|
2514
|
+
var SYNC_START = "\x1B[?2026h";
|
|
2515
|
+
var SYNC_END = "\x1B[?2026l";
|
|
2516
|
+
function overwrite(lines, columns) {
|
|
2517
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2518
|
+
`);
|
|
2519
|
+
}
|
|
2520
|
+
function rowsTaken(lines, columns) {
|
|
2521
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
// ../kit/src/prompt.ts
|
|
2525
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2526
|
+
var MAX_LISTED = 12;
|
|
2527
|
+
function readKeys(input, paste = { active: false }) {
|
|
2528
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2529
|
+
}
|
|
2530
|
+
function roomAfter(question, columns) {
|
|
2531
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
2532
|
+
}
|
|
2533
|
+
function withCaret(colors, line, room, dim = false) {
|
|
2534
|
+
const { before, at, after } = visible(line, room);
|
|
2535
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
2536
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
2537
|
+
}
|
|
2538
|
+
function sharedStart(texts) {
|
|
2539
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
2540
|
+
let length = first.length;
|
|
2541
|
+
for (const chars of rest) {
|
|
2542
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
2543
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
2544
|
+
}
|
|
2545
|
+
return first.slice(0, length).join("");
|
|
2546
|
+
}
|
|
2547
|
+
function listed2(colors, found, columns) {
|
|
2548
|
+
const shared = sharedStart(found);
|
|
2549
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
2550
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
2551
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
2552
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
2553
|
+
}
|
|
2554
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
2555
|
+
let line = { text: "", caret: 0 };
|
|
2556
|
+
let invalid;
|
|
2557
|
+
let completions = [];
|
|
2558
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
2559
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
2560
|
+
let recalled = -1;
|
|
2561
|
+
let draft = line;
|
|
2562
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
2563
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
2564
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
2565
|
+
if (state !== "asking")
|
|
2566
|
+
return [answer(colors, question, state, shown())];
|
|
2567
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
2568
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
2569
|
+
}, (key) => {
|
|
2570
|
+
if (key === "cancel")
|
|
2571
|
+
return "cancel";
|
|
2572
|
+
invalid = undefined;
|
|
2573
|
+
completions = [];
|
|
2574
|
+
if (line.chained === true && endsKills(key))
|
|
2575
|
+
line = { ...line, chained: false };
|
|
2576
|
+
if (key === "tab") {
|
|
2577
|
+
const chars = [...line.text];
|
|
2578
|
+
const before = chars.slice(0, line.caret).join("");
|
|
2579
|
+
const found = complete?.(before) ?? [];
|
|
2580
|
+
const filled = sharedStart(found);
|
|
2581
|
+
if ([...filled].length > [...before].length)
|
|
2582
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
2583
|
+
else
|
|
2584
|
+
completions = found;
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
if (key === "enter") {
|
|
2588
|
+
invalid = validate?.(taken());
|
|
2589
|
+
return invalid === undefined ? "enter" : undefined;
|
|
2590
|
+
}
|
|
2591
|
+
if (key === "up" || key === "down") {
|
|
2592
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
2593
|
+
if (recalled === -1)
|
|
2594
|
+
draft = line;
|
|
2595
|
+
recalled = to;
|
|
2596
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
2597
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2600
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
2601
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
2602
|
+
line = editLine(line, edit);
|
|
2603
|
+
return;
|
|
2604
|
+
});
|
|
2605
|
+
if (!accepted)
|
|
2606
|
+
return;
|
|
2607
|
+
if (remembered !== undefined && taken() !== "")
|
|
2608
|
+
rememberAnswer(remembered, taken());
|
|
2609
|
+
return taken();
|
|
2610
|
+
}
|
|
2611
|
+
function answer(colors, question, state, picked) {
|
|
2612
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2613
|
+
}
|
|
2614
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
2615
|
+
const { stdin, stderr } = terminal;
|
|
2616
|
+
if (!isInteractive(terminal))
|
|
2617
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2618
|
+
const colors = paint(stderr);
|
|
2619
|
+
let current = "asking";
|
|
2620
|
+
let outcome;
|
|
2621
|
+
const columns = () => stderr.columns || 80;
|
|
2622
|
+
const draw = (state, last = false) => {
|
|
2623
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2624
|
+
const rows = rowsTaken(frame, columns());
|
|
2625
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2626
|
+
current = state;
|
|
2627
|
+
};
|
|
2628
|
+
const redraw = () => draw(current);
|
|
2629
|
+
const paste = { active: false };
|
|
2630
|
+
const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
|
|
2631
|
+
const suspend = () => {
|
|
2632
|
+
if (stop === undefined)
|
|
2633
|
+
return;
|
|
2634
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2635
|
+
stdin.setRawMode(false);
|
|
2636
|
+
stop();
|
|
2637
|
+
stdin.setRawMode(true);
|
|
2638
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2639
|
+
};
|
|
2640
|
+
try {
|
|
2641
|
+
stderr.on?.("resize", redraw);
|
|
2642
|
+
stdin.setRawMode(true);
|
|
2643
|
+
stdin.resume();
|
|
2644
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2645
|
+
draw("asking");
|
|
2646
|
+
return await new Promise((resolve) => {
|
|
2647
|
+
function onData(data) {
|
|
2648
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
2649
|
+
if (key === "suspend") {
|
|
2650
|
+
suspend();
|
|
2651
|
+
continue;
|
|
2652
|
+
}
|
|
2653
|
+
const pressed = press(key);
|
|
2654
|
+
if (pressed !== undefined) {
|
|
2655
|
+
settle(pressed);
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
draw("asking");
|
|
2660
|
+
}
|
|
2661
|
+
function onEnd() {
|
|
2662
|
+
settle("cancel");
|
|
2663
|
+
}
|
|
2664
|
+
function settle(settled) {
|
|
2665
|
+
outcome = settled;
|
|
2666
|
+
stdin.off("data", onData);
|
|
2667
|
+
stdin.off("end", onEnd);
|
|
2668
|
+
resolve(settled === "enter");
|
|
2669
|
+
}
|
|
2670
|
+
stdin.on("data", onData);
|
|
2671
|
+
stdin.on("end", onEnd);
|
|
2672
|
+
});
|
|
2673
|
+
} finally {
|
|
2674
|
+
stderr.off?.("resize", redraw);
|
|
2675
|
+
draw(outcome ?? "cancel", true);
|
|
2676
|
+
stderr.write(`
|
|
2677
|
+
\x1B[?25h\x1B[?2004l`);
|
|
2678
|
+
stdin.setRawMode(false);
|
|
2679
|
+
stdin.pause();
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2088
2683
|
// src/commands/edit.ts
|
|
2089
2684
|
var DEFAULT_FILE = ".env";
|
|
2090
2685
|
var TRAILING_NEWLINE = /\r?\n$/;
|
|
@@ -2092,29 +2687,25 @@ var KEY_NAME = /^[A-Z_][\w.-]*$/i;
|
|
|
2092
2687
|
var QUIET = { quiet: { type: "boolean", short: "q", description: "print nothing on success" } };
|
|
2093
2688
|
var setUsage = `ev set KEY [file] [--quiet]
|
|
2094
2689
|
|
|
2095
|
-
Sets KEY in the file (.env by default, created when missing), replacing its line in place or appending one. The value is read from stdin, or from -F <file>, so it never appears in a command line; --empty sets it to an empty value
|
|
2096
|
-
|
|
2097
|
-
Exits 0 when it wrote the key, 1 when it could not, 2 on a usage error.`;
|
|
2690
|
+
Sets KEY in the file (.env by default, created when missing), replacing its line in place or appending one. The value is read from stdin, or from -F <file>, so it never appears in a command line; on a terminal with nothing piped it is asked for, masked as it is typed. --empty sets it to an empty value.`;
|
|
2691
|
+
var SET_EXITS = [[0, "it wrote the key"], [1, "it could not"], [2, "a usage error"], [130, "the prompt was cancelled"]];
|
|
2098
2692
|
var unsetUsage = `ev unset KEY [file] [--quiet]
|
|
2099
2693
|
|
|
2100
|
-
Removes every line setting KEY from the file (.env by default), leaving comments and other lines as they are
|
|
2101
|
-
|
|
2102
|
-
Exits 0 when it removed the key, 1 when the file does not set it, 2 on a usage error.`;
|
|
2694
|
+
Removes every line setting KEY from the file (.env by default), leaving comments and other lines as they are.`;
|
|
2695
|
+
var UNSET_EXITS = [[0, "it removed the key"], [1, "the file does not set it"], [2, "a usage error"]];
|
|
2103
2696
|
var mvUsage = `ev mv KEY --from <file> --to <file> [--quiet]
|
|
2104
2697
|
|
|
2105
|
-
Moves KEY's line from one file to another, as written. Refuses to replace a key the target already sets unless --force
|
|
2106
|
-
|
|
2107
|
-
Exits 0 when it moved the key, 1 when the source lacks it or the target already sets it, 2 on a usage error.`;
|
|
2698
|
+
Moves KEY's line from one file to another, as written. Refuses to replace a key the target already sets unless --force.`;
|
|
2699
|
+
var MV_EXITS = [[0, "it moved the key"], [1, "the source lacks it or the target already sets it"], [2, "a usage error"]];
|
|
2108
2700
|
var cpUsage = `ev cp KEY --from <file> --to <file> [--as NEWKEY] [--quiet]
|
|
2109
2701
|
|
|
2110
|
-
Copies KEY's value from one file to another without printing it, replacing the key's line in the target in place or appending one, and prints the masked result as ev set does. --as stores the copy under another key
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
if (input === "")
|
|
2702
|
+
Copies KEY's value from one file to another without printing it, replacing the key's line in the target in place or appending one, and prints the masked result as ev set does. --as stores the copy under another key.`;
|
|
2703
|
+
var CP_EXITS = [[0, "it copied the key"], [1, "the source lacks it"], [2, "a usage error"]];
|
|
2704
|
+
async function readValue(key, from) {
|
|
2705
|
+
const value = from === undefined && isInteractive() ? await input2(`value of ${key}`, { mask: true }) ?? fail("cancelled, nothing was written", 130) : await readInput(from ?? "-", { noStdin: "pipe the value on stdin or give -F <file>, it is never taken from the command line" });
|
|
2706
|
+
if (value === "")
|
|
2116
2707
|
fail("the value is empty, nothing was written: --empty sets an empty value");
|
|
2117
|
-
return
|
|
2708
|
+
return value.replace(TRAILING_NEWLINE, "");
|
|
2118
2709
|
}
|
|
2119
2710
|
function checkKey(key) {
|
|
2120
2711
|
if (!KEY_NAME.test(key))
|
|
@@ -2128,7 +2719,7 @@ async function set(args) {
|
|
|
2128
2719
|
file: { type: "string", short: "F", description: "read the value from this file instead of stdin" },
|
|
2129
2720
|
empty: { type: "boolean", description: "set an empty value, reading nothing" },
|
|
2130
2721
|
...QUIET
|
|
2131
|
-
});
|
|
2722
|
+
}, { exits: SET_EXITS });
|
|
2132
2723
|
const [key, target = DEFAULT_FILE] = parsed.positionals;
|
|
2133
2724
|
if (key === undefined)
|
|
2134
2725
|
fail(`missing KEY
|
|
@@ -2137,7 +2728,7 @@ ${setUsage}`);
|
|
|
2137
2728
|
if (parsed.values.empty === true && parsed.values.file !== undefined)
|
|
2138
2729
|
fail("--empty and -F exclude each other");
|
|
2139
2730
|
checkKey(key);
|
|
2140
|
-
const value = parsed.values.empty === true ? "" : await readValue(parsed.values.file);
|
|
2731
|
+
const value = parsed.values.empty === true ? "" : await readValue(key, parsed.values.file);
|
|
2141
2732
|
const file = await withLocks([target], async () => {
|
|
2142
2733
|
const current = await readOrEmpty(target);
|
|
2143
2734
|
setLine(current, key, value);
|
|
@@ -2150,7 +2741,7 @@ ${setUsage}`);
|
|
|
2150
2741
|
return 0;
|
|
2151
2742
|
}
|
|
2152
2743
|
async function unset(args) {
|
|
2153
|
-
const parsed = parse(args, unsetUsage, QUIET);
|
|
2744
|
+
const parsed = parse(args, unsetUsage, QUIET, { exits: UNSET_EXITS });
|
|
2154
2745
|
const [key, target = DEFAULT_FILE] = parsed.positionals;
|
|
2155
2746
|
if (key === undefined)
|
|
2156
2747
|
fail(`missing KEY
|
|
@@ -2191,7 +2782,7 @@ async function mv(args) {
|
|
|
2191
2782
|
to: { type: "string", description: "the file to put KEY in, created when missing" },
|
|
2192
2783
|
force: { type: "boolean", description: "replace KEY when the target already sets it" },
|
|
2193
2784
|
...QUIET
|
|
2194
|
-
});
|
|
2785
|
+
}, { exits: MV_EXITS });
|
|
2195
2786
|
const [key] = parsed.positionals;
|
|
2196
2787
|
const { from, to, force } = parsed.values;
|
|
2197
2788
|
if (key === undefined || from === undefined || to === undefined)
|
|
@@ -2213,7 +2804,7 @@ async function cp(args) {
|
|
|
2213
2804
|
to: { type: "string", description: "the file to put the copy in, created when missing" },
|
|
2214
2805
|
as: { type: "string", description: "store the copy under this key instead" },
|
|
2215
2806
|
...QUIET
|
|
2216
|
-
});
|
|
2807
|
+
}, { exits: CP_EXITS });
|
|
2217
2808
|
const [key] = parsed.positionals;
|
|
2218
2809
|
const { from, to, as } = parsed.values;
|
|
2219
2810
|
if (key === undefined || from === undefined || to === undefined)
|
|
@@ -2229,11 +2820,11 @@ ${cpUsage}`);
|
|
|
2229
2820
|
|
|
2230
2821
|
// src/commands/pins.ts
|
|
2231
2822
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
2232
|
-
import { join as
|
|
2823
|
+
import { join as join12, resolve as resolve5 } from "path";
|
|
2233
2824
|
|
|
2234
2825
|
// src/pins.ts
|
|
2235
2826
|
import { readdir as readdir3, readFile } from "fs/promises";
|
|
2236
|
-
import { join as
|
|
2827
|
+
import { join as join11, relative as relative2 } from "path";
|
|
2237
2828
|
var OPTIONAL2 = /^\s*([A-Z][A-Z0-9_]*)\s*:\s*s\.Optional\(/gm;
|
|
2238
2829
|
var REACHING = /(?:URL|URI|TOKEN|KEY|SECRET|PASSWORD|DSN|_HOST)(?:_FILE)?$/;
|
|
2239
2830
|
var SELF = /(?:^|_)(?:PUBLIC|SITE|BASE|APP)_URL$/;
|
|
@@ -2262,7 +2853,7 @@ async function walk(folder, keep) {
|
|
|
2262
2853
|
for (const entry of entries) {
|
|
2263
2854
|
if (SKIPPED.has(entry.name))
|
|
2264
2855
|
continue;
|
|
2265
|
-
const path =
|
|
2856
|
+
const path = join11(folder, entry.name);
|
|
2266
2857
|
if (entry.isDirectory())
|
|
2267
2858
|
found.push(...await walk(path, keep));
|
|
2268
2859
|
else if (entry.isFile() && keep(entry.name))
|
|
@@ -2273,7 +2864,7 @@ async function walk(folder, keep) {
|
|
|
2273
2864
|
async function testFiles(folder) {
|
|
2274
2865
|
const found = [];
|
|
2275
2866
|
for (const root of TEST_ROOTS) {
|
|
2276
|
-
found.push(...await walk(
|
|
2867
|
+
found.push(...await walk(join11(folder, root), (name) => TEST_FILE.test(name)));
|
|
2277
2868
|
}
|
|
2278
2869
|
return found;
|
|
2279
2870
|
}
|
|
@@ -2341,7 +2932,7 @@ function reachesOutside(name) {
|
|
|
2341
2932
|
}
|
|
2342
2933
|
async function schemaFile(folder) {
|
|
2343
2934
|
for (const candidate of SCHEMA_CANDIDATES) {
|
|
2344
|
-
const path =
|
|
2935
|
+
const path = join11(folder, candidate);
|
|
2345
2936
|
if (await exists(path) && (await readFile(path, "utf8")).includes("defineEnv("))
|
|
2346
2937
|
return path;
|
|
2347
2938
|
}
|
|
@@ -2352,7 +2943,7 @@ async function testEnvKeys(folder) {
|
|
|
2352
2943
|
for (const entry of await readdir3(folder, { withFileTypes: true })) {
|
|
2353
2944
|
if (!entry.isFile() || !ENV_TEST.test(entry.name))
|
|
2354
2945
|
continue;
|
|
2355
|
-
for (const line of parseDotenv(await readFile(
|
|
2946
|
+
for (const line of parseDotenv(await readFile(join11(folder, entry.name), "utf8")).lines) {
|
|
2356
2947
|
if (line.key !== undefined)
|
|
2357
2948
|
keys.add(line.key);
|
|
2358
2949
|
}
|
|
@@ -2360,7 +2951,7 @@ async function testEnvKeys(folder) {
|
|
|
2360
2951
|
return keys;
|
|
2361
2952
|
}
|
|
2362
2953
|
async function pinningPreload(folder) {
|
|
2363
|
-
const path =
|
|
2954
|
+
const path = join11(folder, "bunfig.toml");
|
|
2364
2955
|
if (!await exists(path))
|
|
2365
2956
|
return;
|
|
2366
2957
|
let config;
|
|
@@ -2371,7 +2962,7 @@ async function pinningPreload(folder) {
|
|
|
2371
2962
|
}
|
|
2372
2963
|
const preloads = [config.test?.preload, config.preload].flat().filter((entry) => typeof entry === "string" && entry.startsWith("."));
|
|
2373
2964
|
for (const preload of preloads) {
|
|
2374
|
-
const file =
|
|
2965
|
+
const file = join11(folder, preload);
|
|
2375
2966
|
if (!await exists(file))
|
|
2376
2967
|
continue;
|
|
2377
2968
|
const source = await readFile(file, "utf8");
|
|
@@ -2412,8 +3003,8 @@ Checks that an app's tests pin the env that reaches outside.
|
|
|
2412
3003
|
Reads the app's env schema (the file calling defineEnv, src/env.ts) and lists its optional URL, key, token, secret, password and host variables, then the ones no \`.env.test\` entry, test-level overrideEnv or local bunfig preload dropping what .env sets pins, and each test file that calls testSite or proxyKeyTests without pinning them all.
|
|
2413
3004
|
A file whose pages reach none of them says so with a \`// ev pins: none reached, <why>\` comment.
|
|
2414
3005
|
The dir is an app, or a monorepo holding apps one level down (the current folder by default).
|
|
2415
|
-
Reads variable names only, never a value
|
|
2416
|
-
|
|
3006
|
+
Reads variable names only, never a value.`;
|
|
3007
|
+
var EXITS2 = [[0, "everything is pinned"], [1, "something is not"], [2, "a usage error"]];
|
|
2417
3008
|
var options2 = {
|
|
2418
3009
|
json: jsonOption("each app with its reaching, unpinned variables and flagged test files"),
|
|
2419
3010
|
except: { type: "string", description: "comma-separated variables to leave out, as ones that only link back to the app" }
|
|
@@ -2433,7 +3024,7 @@ async function apps(dir, except) {
|
|
|
2433
3024
|
for (const entry of (await readdir4(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2434
3025
|
if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
|
|
2435
3026
|
continue;
|
|
2436
|
-
const app = await checkApp(
|
|
3027
|
+
const app = await checkApp(join12(dir, entry.name), except);
|
|
2437
3028
|
if (app !== undefined)
|
|
2438
3029
|
found.push(app);
|
|
2439
3030
|
}
|
|
@@ -2446,9 +3037,9 @@ function name(app, root) {
|
|
|
2446
3037
|
return app.app === root ? app.app.split("/").at(-1) ?? app.app : app.app.slice(root.length + 1);
|
|
2447
3038
|
}
|
|
2448
3039
|
async function pins(args) {
|
|
2449
|
-
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"] });
|
|
3040
|
+
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"], exits: EXITS2 });
|
|
2450
3041
|
const json = parsed.values.json === true;
|
|
2451
|
-
const root =
|
|
3042
|
+
const root = resolve5(parsed.positionals[0] ?? ".");
|
|
2452
3043
|
const except = new Set((parsed.values.except ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== ""));
|
|
2453
3044
|
if (!await isFolder2(root))
|
|
2454
3045
|
fail(`${root} is not a folder`);
|
|
@@ -2480,16 +3071,14 @@ var listUsage = `ev list [file]
|
|
|
2480
3071
|
|
|
2481
3072
|
Prints every key of the folder's .env* files, or of one file, with secret values masked: a few leading characters and the length under a key named like TOKEN, SECRET, PASSWORD, PASS, PWD, KEY, PRIVATE, DSN, AUTH, SALT or COOKIE, any value equal to a secret of the folder's .env* files, and the password and tokens of any URL.
|
|
2482
3073
|
|
|
2483
|
-
--json prints [{file, key, value, secret}], value masked and secret true when a value was
|
|
2484
|
-
|
|
2485
|
-
Exits 0 when it printed them, 1 when there is no .env* file, 2 on a usage error.`;
|
|
3074
|
+
--json prints [{file, key, value, secret}], value masked and secret true when a value was.`;
|
|
3075
|
+
var LIST_EXITS = [[0, "it printed them"], [1, "there is no .env* file"], [2, "a usage error"]];
|
|
2486
3076
|
var getUsage = `ev get KEY [file]
|
|
2487
3077
|
|
|
2488
3078
|
Prints the masked value of one key, from every .env* file that sets it or from one file.
|
|
2489
3079
|
|
|
2490
|
-
--json prints [{file, key, value, secret}] for each file that sets it
|
|
2491
|
-
|
|
2492
|
-
Exits 0 when the key is set, 1 when it is not set anywhere, 2 on a usage error.`;
|
|
3080
|
+
--json prints [{file, key, value, secret}] for each file that sets it.`;
|
|
3081
|
+
var GET_EXITS = [[0, "the key is set"], [1, "it is not set anywhere"], [2, "a usage error"]];
|
|
2493
3082
|
function display(key, value, known) {
|
|
2494
3083
|
return maskValue(key, value, known).replaceAll(`
|
|
2495
3084
|
`, "\\n").replaceAll("\r", "\\r");
|
|
@@ -2522,7 +3111,7 @@ async function readAll(names) {
|
|
|
2522
3111
|
return { files, known: await loadKnown(process.cwd(), files.map(([, file]) => file)) };
|
|
2523
3112
|
}
|
|
2524
3113
|
async function list(args) {
|
|
2525
|
-
const parsed = parse(args, listUsage, jsonFlag2);
|
|
3114
|
+
const parsed = parse(args, listUsage, jsonFlag2, { exits: LIST_EXITS });
|
|
2526
3115
|
const [file] = parsed.positionals;
|
|
2527
3116
|
const names = file === undefined ? await envFiles() : [file];
|
|
2528
3117
|
if (names.length === 0)
|
|
@@ -2540,7 +3129,7 @@ async function list(args) {
|
|
|
2540
3129
|
return 0;
|
|
2541
3130
|
}
|
|
2542
3131
|
async function get(args) {
|
|
2543
|
-
const parsed = parse(args, getUsage, jsonFlag2);
|
|
3132
|
+
const parsed = parse(args, getUsage, jsonFlag2, { exits: GET_EXITS });
|
|
2544
3133
|
const [key, file] = parsed.positionals;
|
|
2545
3134
|
if (key === undefined)
|
|
2546
3135
|
fail(`missing KEY
|
|
@@ -2563,19 +3152,17 @@ var grepUsage = `ev grep [-i] <regex> [file...]
|
|
|
2563
3152
|
|
|
2564
3153
|
Prints the keys matching the regular expression, from the folder's .env* files or the files given, with their values masked as ev list does. The regex is matched against the key only, never the value: \`ev grep '^DATABASE_'\` instead of \`grep ^DATABASE_ .env\`.
|
|
2565
3154
|
|
|
2566
|
-
--json prints [{file, key, value, secret}]
|
|
2567
|
-
|
|
2568
|
-
Exits 0 when a key matches, 1 when none does, 2 on a usage error.`;
|
|
3155
|
+
--json prints [{file, key, value, secret}].`;
|
|
3156
|
+
var GREP_EXITS = [[0, "a key matches"], [1, "none does"], [2, "a usage error"]];
|
|
2569
3157
|
var showUsage = `ev show <rev>:<file>
|
|
2570
3158
|
|
|
2571
3159
|
Prints every key of an env file as a git revision holds it, values masked as ev list does: \`ev show HEAD~1:api/.env\` instead of \`git show HEAD~1:api/.env\`.
|
|
2572
3160
|
|
|
2573
|
-
--json prints [{file, key, value, secret}]
|
|
2574
|
-
|
|
2575
|
-
Exits 0 when it printed them, 1 when git cannot show the file, 2 on a usage error.`;
|
|
3161
|
+
--json prints [{file, key, value, secret}].`;
|
|
3162
|
+
var SHOW_EXITS = [[0, "it printed them"], [1, "git cannot show the file"], [2, "a usage error"]];
|
|
2576
3163
|
var REVISION = /^([^:]+):(.+)$/;
|
|
2577
3164
|
async function grep(args) {
|
|
2578
|
-
const parsed = parse(args, grepUsage, { "ignore-case": { type: "boolean", short: "i", description: "match the key whatever its case" }, ...jsonFlag2 });
|
|
3165
|
+
const parsed = parse(args, grepUsage, { "ignore-case": { type: "boolean", short: "i", description: "match the key whatever its case" }, ...jsonFlag2 }, { exits: GREP_EXITS });
|
|
2579
3166
|
const [source, ...given] = parsed.positionals;
|
|
2580
3167
|
if (source === undefined)
|
|
2581
3168
|
fail(`missing the regex
|
|
@@ -2602,7 +3189,7 @@ ${grepUsage}`);
|
|
|
2602
3189
|
return 0;
|
|
2603
3190
|
}
|
|
2604
3191
|
async function show(args) {
|
|
2605
|
-
const parsed = parse(args, showUsage, jsonFlag2);
|
|
3192
|
+
const parsed = parse(args, showUsage, jsonFlag2, { exits: SHOW_EXITS });
|
|
2606
3193
|
const [target] = parsed.positionals;
|
|
2607
3194
|
const [, revision, path] = REVISION.exec(target ?? "") ?? [];
|
|
2608
3195
|
if (revision === undefined || path === undefined)
|
|
@@ -2625,7 +3212,7 @@ ${showUsage}`);
|
|
|
2625
3212
|
}
|
|
2626
3213
|
|
|
2627
3214
|
// src/commands/redact.ts
|
|
2628
|
-
import
|
|
3215
|
+
import process21 from "process";
|
|
2629
3216
|
|
|
2630
3217
|
// src/redactor.ts
|
|
2631
3218
|
var DIFF_START = /^(?:diff --git |@@ )/;
|
|
@@ -2746,15 +3333,14 @@ function check(text, known) {
|
|
|
2746
3333
|
var usage4 = `redact [--check]
|
|
2747
3334
|
|
|
2748
3335
|
Copies stdin to stdout line by line with secrets masked: known token formats (GitHub, GitLab, Slack, AWS, npm, Stripe, Google and SendGrid keys, sk-, JWTs, Authorization headers, password= and secret= pairs), private key blocks, the password and the tokens of any URL and the values of secret-looking keys in this folder's .env* files.
|
|
2749
|
-
--check prints nothing of the input and lists the file and line of each secret found, exiting 1 when there is any: \`git diff --cached | redact --check
|
|
2750
|
-
|
|
2751
|
-
Exits 0 when it copied the input or found no secret, 1 when --check finds one, 2 on a usage error.`;
|
|
3336
|
+
--check prints nothing of the input and lists the file and line of each secret found, exiting 1 when there is any: \`git diff --cached | redact --check\`.`;
|
|
3337
|
+
var EXITS3 = [[0, "it copied the input or found no secret"], [1, "--check finds one"], [2, "a usage error"]];
|
|
2752
3338
|
var options3 = {
|
|
2753
3339
|
check: { type: "boolean", description: "list where secrets are instead of masking them, exit 1 when found" },
|
|
2754
3340
|
"no-env": { type: "boolean", description: "do not search for the values of the .env* files" }
|
|
2755
3341
|
};
|
|
2756
3342
|
async function redact(args) {
|
|
2757
|
-
const parsed = parse(args, usage4, options3, { replaces: "printing a command's secrets into a log or a transcript", examples: [["docker compose config | redact", "the resolved compose file, secrets masked"], ["git diff --cached | redact --check", "refuse a commit carrying a secret"]] });
|
|
3343
|
+
const parsed = parse(args, usage4, options3, { exits: EXITS3, replaces: "printing a command's secrets into a log or a transcript", examples: [["docker compose config | redact", "the resolved compose file, secrets masked"], ["git diff --cached | redact --check", "refuse a commit carrying a secret"]] });
|
|
2758
3344
|
const known = parsed.values["no-env"] === true ? undefined : await loadKnown();
|
|
2759
3345
|
if (parsed.values.check === true) {
|
|
2760
3346
|
const findings = check(await readInput("-"), known);
|
|
@@ -2765,13 +3351,13 @@ async function redact(args) {
|
|
|
2765
3351
|
const redactor = new Redactor(known);
|
|
2766
3352
|
const decoder = new TextDecoder;
|
|
2767
3353
|
for await (const chunk of Bun.stdin.stream())
|
|
2768
|
-
|
|
2769
|
-
|
|
3354
|
+
process21.stdout.write(redactor.push(decoder.decode(chunk, { stream: true })));
|
|
3355
|
+
process21.stdout.write(redactor.push(decoder.decode()) + redactor.end());
|
|
2770
3356
|
return 0;
|
|
2771
3357
|
}
|
|
2772
3358
|
|
|
2773
3359
|
// src/ev.ts
|
|
2774
|
-
|
|
3360
|
+
process22.exitCode = await runCli({
|
|
2775
3361
|
name: "ev",
|
|
2776
3362
|
about: ".env files listed and edited with secrets masked",
|
|
2777
3363
|
replaces: "cat .env, grep on env files and editing them by hand",
|