@kaynooo/cli-env 0.13.1 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ev.js +207 -115
- package/dist/redact.js +157 -55
- package/package.json +2 -2
- package/src/commands/audit.ts +5 -3
- package/src/commands/compare.ts +7 -6
- package/src/commands/edit.ts +13 -12
- 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 process19 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -374,6 +374,23 @@ var STATUS_WORDS = {
|
|
|
374
374
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
375
375
|
|
|
376
376
|
// ../kit/src/format.ts
|
|
377
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
378
|
+
function formatSeconds(total) {
|
|
379
|
+
let rest = Math.max(0, Math.round(total));
|
|
380
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
381
|
+
const amount = Math.floor(rest / size);
|
|
382
|
+
rest -= amount * size;
|
|
383
|
+
return `${amount}${unit}`;
|
|
384
|
+
});
|
|
385
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
386
|
+
if (first === -1)
|
|
387
|
+
return "0s";
|
|
388
|
+
const next = amounts[first + 1];
|
|
389
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
390
|
+
}
|
|
391
|
+
function formatDuration(ms) {
|
|
392
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
393
|
+
}
|
|
377
394
|
function upTo(text, separator) {
|
|
378
395
|
const end = text.indexOf(separator);
|
|
379
396
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -434,24 +451,20 @@ function printJson(value) {
|
|
|
434
451
|
|
|
435
452
|
// ../kit/src/help.ts
|
|
436
453
|
import process8 from "process";
|
|
437
|
-
var OPTIONAL =
|
|
454
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
438
455
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
439
456
|
var FULL_STOP = /\.$/;
|
|
440
457
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
441
458
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
442
459
|
}
|
|
443
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
444
|
-
return [usageLine(usage, colors),
|
|
460
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
461
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
445
462
|
`);
|
|
446
463
|
}
|
|
447
464
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
448
465
|
if (exits.length === 0)
|
|
449
466
|
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}`];
|
|
467
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
455
468
|
}
|
|
456
469
|
function wantsHelpJson(env = process8.env) {
|
|
457
470
|
return env.KIT_HELP === "json";
|
|
@@ -477,29 +490,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
477
490
|
return [];
|
|
478
491
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
479
492
|
}
|
|
493
|
+
var MAX_INLINE_CHOICES = 24;
|
|
480
494
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
481
495
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
482
496
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
483
|
-
const
|
|
497
|
+
const choices = option.choices?.join("|");
|
|
498
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
499
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
484
500
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
485
501
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
486
|
-
|
|
502
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
503
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
487
504
|
});
|
|
488
505
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
489
506
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
490
507
|
}
|
|
491
508
|
|
|
492
509
|
// ../kit/src/text.ts
|
|
493
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
494
510
|
function distance(a, b) {
|
|
495
|
-
|
|
496
|
-
|
|
511
|
+
const left = [...a];
|
|
512
|
+
const right = [...b];
|
|
513
|
+
let before = [];
|
|
514
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
515
|
+
for (const [i, x] of left.entries()) {
|
|
497
516
|
const current = [i + 1];
|
|
498
|
-
for (const [j,
|
|
499
|
-
|
|
517
|
+
for (const [j, y] of right.entries()) {
|
|
518
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
519
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
520
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
521
|
+
current.push(cost);
|
|
522
|
+
}
|
|
523
|
+
before = previous;
|
|
500
524
|
previous = current;
|
|
501
525
|
}
|
|
502
|
-
return previous[
|
|
526
|
+
return previous[right.length] ?? 0;
|
|
503
527
|
}
|
|
504
528
|
function closest(name, names) {
|
|
505
529
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -739,21 +763,63 @@ function nearestOption(message, options, allowNegative) {
|
|
|
739
763
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
740
764
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
741
765
|
}
|
|
766
|
+
// ../kit/src/argv.ts
|
|
767
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
768
|
+
import { resolve as resolve3 } from "path";
|
|
769
|
+
import process11 from "process";
|
|
770
|
+
function commandLine() {
|
|
771
|
+
try {
|
|
772
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
773
|
+
} catch {
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function realPath(word) {
|
|
778
|
+
try {
|
|
779
|
+
return realpathSync(resolve3(word));
|
|
780
|
+
} catch {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
785
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
786
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
787
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
788
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
789
|
+
}
|
|
742
790
|
// ../kit/src/progress.ts
|
|
743
791
|
var ESC = String.fromCharCode(27);
|
|
744
792
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
745
793
|
var RESET_STYLE = `${ESC}[0m`;
|
|
746
794
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
747
795
|
// ../kit/src/cli.ts
|
|
748
|
-
import { readFileSync as
|
|
796
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
749
797
|
import { dirname as dirname3, join as join5 } from "path";
|
|
798
|
+
import process14 from "process";
|
|
799
|
+
|
|
800
|
+
// ../kit/src/notify.ts
|
|
750
801
|
import process12 from "process";
|
|
802
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
803
|
+
var CANCELLED = 130;
|
|
804
|
+
function base64(text) {
|
|
805
|
+
return Buffer.from(text).toString("base64");
|
|
806
|
+
}
|
|
807
|
+
function notification(title, body, env = process12.env) {
|
|
808
|
+
const id = `kit${process12.pid}`;
|
|
809
|
+
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\\`];
|
|
810
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
811
|
+
}
|
|
812
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
813
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
814
|
+
return;
|
|
815
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
816
|
+
}
|
|
751
817
|
|
|
752
818
|
// ../kit/src/usage.ts
|
|
753
819
|
import { appendFileSync, mkdirSync } from "fs";
|
|
754
820
|
import { homedir as homedir3 } from "os";
|
|
755
821
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
756
|
-
import
|
|
822
|
+
import process13 from "process";
|
|
757
823
|
|
|
758
824
|
// ../kit/src/logs.ts
|
|
759
825
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -767,14 +833,14 @@ var usageError;
|
|
|
767
833
|
function noteUsageError(message) {
|
|
768
834
|
usageError = message;
|
|
769
835
|
}
|
|
770
|
-
function stateHome(env =
|
|
836
|
+
function stateHome(env = process13.env) {
|
|
771
837
|
const dir = env.XDG_STATE_HOME;
|
|
772
838
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
773
839
|
}
|
|
774
|
-
function usagePath(env =
|
|
840
|
+
function usagePath(env = process13.env) {
|
|
775
841
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
776
842
|
}
|
|
777
|
-
function usageRecorded(env =
|
|
843
|
+
function usageRecorded(env = process13.env) {
|
|
778
844
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
779
845
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
780
846
|
}
|
|
@@ -788,7 +854,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
788
854
|
usageError = undefined;
|
|
789
855
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
790
856
|
}
|
|
791
|
-
function recordUsage(entry, env =
|
|
857
|
+
function recordUsage(entry, env = process13.env) {
|
|
792
858
|
if (!usageRecorded(env))
|
|
793
859
|
return;
|
|
794
860
|
try {
|
|
@@ -865,7 +931,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
865
931
|
header(colors, summary),
|
|
866
932
|
"",
|
|
867
933
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
868
|
-
...replacesRows(replaces, colors),
|
|
869
934
|
"",
|
|
870
935
|
...await commandRows(commands, colors),
|
|
871
936
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -879,8 +944,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
879
944
|
`);
|
|
880
945
|
}
|
|
881
946
|
function printError(prefix, message, hint, cause) {
|
|
882
|
-
const colors = paint(
|
|
883
|
-
const styled = takesControlCodes(
|
|
947
|
+
const colors = paint(process14.stderr);
|
|
948
|
+
const styled = takesControlCodes(process14.stderr);
|
|
884
949
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
885
950
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
886
951
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -923,11 +988,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
923
988
|
}
|
|
924
989
|
}
|
|
925
990
|
if (name === undefined && level.path.length > 1) {
|
|
926
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
991
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
927
992
|
return 2;
|
|
928
993
|
}
|
|
929
994
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
930
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
995
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
931
996
|
return 0;
|
|
932
997
|
}
|
|
933
998
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -983,24 +1048,24 @@ function candidateLine(candidate) {
|
|
|
983
1048
|
}
|
|
984
1049
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
985
1050
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
986
|
-
|
|
1051
|
+
const typed = [];
|
|
987
1052
|
let at = 0;
|
|
988
1053
|
while (at < before.length) {
|
|
989
1054
|
const word = before[at];
|
|
990
1055
|
if (word === "--") {
|
|
991
|
-
|
|
1056
|
+
typed.push(...before.slice(at + 1));
|
|
992
1057
|
break;
|
|
993
1058
|
}
|
|
994
1059
|
if (!word.startsWith("-"))
|
|
995
|
-
|
|
1060
|
+
typed.push(word);
|
|
996
1061
|
else if (takesValue(word))
|
|
997
1062
|
at++;
|
|
998
1063
|
at++;
|
|
999
1064
|
}
|
|
1000
1065
|
const last = positionals.at(-1);
|
|
1001
|
-
if (
|
|
1002
|
-
return positionals[
|
|
1003
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1066
|
+
if (typed.length < positionals.length)
|
|
1067
|
+
return { name: positionals[typed.length], typed };
|
|
1068
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1004
1069
|
}
|
|
1005
1070
|
async function leafCandidates(run, words) {
|
|
1006
1071
|
const completing = await completingOf(run);
|
|
@@ -1008,12 +1073,12 @@ async function leafCandidates(run, words) {
|
|
|
1008
1073
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1009
1074
|
const flag = words.at(-2);
|
|
1010
1075
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1076
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1011
1077
|
if (option?.type === "string") {
|
|
1012
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1078
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1013
1079
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1014
1080
|
}
|
|
1015
|
-
const
|
|
1016
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1081
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1017
1082
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1018
1083
|
}
|
|
1019
1084
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1044,9 +1109,13 @@ async function printCandidates(found) {
|
|
|
1044
1109
|
return 0;
|
|
1045
1110
|
}
|
|
1046
1111
|
function packageVersion(entry = Bun.main) {
|
|
1047
|
-
|
|
1112
|
+
let resolved = entry;
|
|
1113
|
+
try {
|
|
1114
|
+
resolved = realpathSync2(entry);
|
|
1115
|
+
} catch {}
|
|
1116
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1048
1117
|
try {
|
|
1049
|
-
const { version } = JSON.parse(
|
|
1118
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1050
1119
|
if (typeof version === "string")
|
|
1051
1120
|
return version;
|
|
1052
1121
|
} catch {}
|
|
@@ -1054,14 +1123,17 @@ function packageVersion(entry = Bun.main) {
|
|
|
1054
1123
|
return "0.0.0";
|
|
1055
1124
|
}
|
|
1056
1125
|
}
|
|
1057
|
-
async function runCli(cli, argv =
|
|
1126
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1058
1127
|
const version = cli.version ?? packageVersion();
|
|
1059
1128
|
if (argv[0] === COMPLETE)
|
|
1060
1129
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1130
|
+
const started = performance.now();
|
|
1061
1131
|
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 });
|
|
1132
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1133
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1062
1134
|
if (cli.usage !== false) {
|
|
1063
1135
|
try {
|
|
1064
|
-
recordUsage(usageEntry(cli.name,
|
|
1136
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1065
1137
|
} catch {}
|
|
1066
1138
|
}
|
|
1067
1139
|
return code;
|
|
@@ -1081,7 +1153,7 @@ function commandPath(scope, argv) {
|
|
|
1081
1153
|
}
|
|
1082
1154
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1083
1155
|
}
|
|
1084
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1156
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1085
1157
|
if (argv[0] === COMPLETE)
|
|
1086
1158
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1087
1159
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1089,11 +1161,13 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1089
1161
|
return 0;
|
|
1090
1162
|
}
|
|
1091
1163
|
let code;
|
|
1164
|
+
const started = performance.now();
|
|
1092
1165
|
try {
|
|
1093
1166
|
code = await run(argv);
|
|
1094
1167
|
} catch (error) {
|
|
1095
1168
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1096
1169
|
}
|
|
1170
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1097
1171
|
if (usage !== false) {
|
|
1098
1172
|
try {
|
|
1099
1173
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1130,8 +1204,8 @@ var SESSION_FILES = new Glob("*.json");
|
|
|
1130
1204
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1131
1205
|
// src/commands/audit.ts
|
|
1132
1206
|
import { stat as stat4 } from "fs/promises";
|
|
1133
|
-
import { relative, resolve as
|
|
1134
|
-
import
|
|
1207
|
+
import { relative, resolve as resolve4 } from "path";
|
|
1208
|
+
import process16 from "process";
|
|
1135
1209
|
|
|
1136
1210
|
// ../kit/src/shell.ts
|
|
1137
1211
|
var SEPARATORS = new Set([`
|
|
@@ -1245,7 +1319,8 @@ function parseDotenv(text) {
|
|
|
1245
1319
|
let body = start.slice(1);
|
|
1246
1320
|
let raw = line;
|
|
1247
1321
|
let end = closingQuote(body, quote);
|
|
1248
|
-
|
|
1322
|
+
const first = index;
|
|
1323
|
+
while (end === -1 && index + 1 < physical.length && !ASSIGNMENT.test(physical[index + 1] ?? "")) {
|
|
1249
1324
|
index++;
|
|
1250
1325
|
body += `
|
|
1251
1326
|
${(physical[index] ?? "").replace(CARRIAGE_RETURN, "")}`;
|
|
@@ -1253,6 +1328,11 @@ ${(physical[index] ?? "").replace(CARRIAGE_RETURN, "")}`;
|
|
|
1253
1328
|
${physical[index] ?? ""}`;
|
|
1254
1329
|
end = closingQuote(body, quote);
|
|
1255
1330
|
}
|
|
1331
|
+
if (end === -1 && index + 1 < physical.length) {
|
|
1332
|
+
index = first;
|
|
1333
|
+
lines.push({ raw: line, key, value: unescapeDollar(start.replace(INLINE_COMMENT, "").trim()), unterminated: true });
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1256
1336
|
const inner = end === -1 ? body : body.slice(0, end);
|
|
1257
1337
|
lines.push({ raw, key, value: quote === '"' ? unescapeDouble(inner) : unescapeDollar(inner) });
|
|
1258
1338
|
}
|
|
@@ -1318,9 +1398,30 @@ var ESCAPE2 = /[.*+?^${}()|[\]\\]/g;
|
|
|
1318
1398
|
function isPlaceholder(value) {
|
|
1319
1399
|
return PLACEHOLDER.test(value) || PLAIN_VALUE.test(value);
|
|
1320
1400
|
}
|
|
1401
|
+
var STRONG_NAME = "password|passwd|secret|api[_-]?key|access[_-]?key|private[_-]?key|account[_-]?key|shared[_-]?access[_-]?key";
|
|
1402
|
+
var WEAK_NAME = "token|credentials?|auth";
|
|
1403
|
+
var PLAIN_WORD = /^[a-z]+$/i;
|
|
1404
|
+
var AFTER_COLON = /:\s*$/;
|
|
1405
|
+
var DIGIT = /\d/;
|
|
1406
|
+
var KEY_VALUE_GAP = "\\s*[:=]\\s*";
|
|
1407
|
+
function isProse(value, before) {
|
|
1408
|
+
return isPlaceholder(value) || AFTER_COLON.test(before) && PLAIN_WORD.test(value);
|
|
1409
|
+
}
|
|
1410
|
+
function isWeak(value, before) {
|
|
1411
|
+
return isProse(value, before) || !(DIGIT.test(value) || value.length >= 16);
|
|
1412
|
+
}
|
|
1413
|
+
function keyed(names, value) {
|
|
1414
|
+
return new RegExp(`(?<![\\w-])["']?(?:[\\w-]{0,30}[_-])?(?:${names})(?:[_-][\\w-]{0,30})?["']?${KEY_VALUE_GAP}${value}`, "dgi");
|
|
1415
|
+
}
|
|
1321
1416
|
var TOKEN_FORMATS = [
|
|
1322
1417
|
{ kind: "GitHub token", pattern: /\b(?:gh[pousr]_|github_pat_)\w{20,}/dg },
|
|
1323
|
-
{ kind: "GitLab token", pattern: /\
|
|
1418
|
+
{ kind: "GitLab token", pattern: /\bgl(?:pat|rt|dt|ptt)-[\w-]{20,}/dg },
|
|
1419
|
+
{ kind: "Hugging Face token", pattern: /\bhf_[A-Za-z]{30,}/dg },
|
|
1420
|
+
{ kind: "webhook secret", pattern: /\bwhsec_\w{20,}/dg },
|
|
1421
|
+
{ kind: "DigitalOcean token", pattern: /\bdop_v1_\w{20,}/dg },
|
|
1422
|
+
{ kind: "Shopify token", pattern: /\bshp(?:at|ca|pa|ss)_\w{20,}/dg },
|
|
1423
|
+
{ kind: "password", pattern: /\bmysql(?:dump|admin)?\s+(?:\S+\s+)*?-p([^\s"'|;&-]\S{3,})/dg },
|
|
1424
|
+
{ kind: "password", pattern: /\bsshpass\s+(?:-[a-oq-z]\s+)*-p\s*([^\s"'|;&]{4,})/dg },
|
|
1324
1425
|
{ kind: "API key", pattern: /\bsk-[\w-]{20,}/dg },
|
|
1325
1426
|
{ kind: "Slack token", pattern: /\bx(?:ox[abprs]|app)-[\w-]{10,}/dg },
|
|
1326
1427
|
{ kind: "JWT", pattern: /\beyJ[\w-]+\.[\w-]+\.[\w-]+/dg },
|
|
@@ -1331,8 +1432,10 @@ var TOKEN_FORMATS = [
|
|
|
1331
1432
|
{ kind: "SendGrid key", pattern: /\bSG\.[\w-]{16,}\.[\w-]{16,}/dg },
|
|
1332
1433
|
{ kind: "Authorization header", pattern: /\bAuthorization["']?\s*[:=]\s*["']?(?:Bearer|Basic|Token|Digest)\s+([^\s"',;]{8,})/dgi, skip: isPlaceholder },
|
|
1333
1434
|
{ kind: "Bearer token", pattern: /\bBearer\s+((?=[\w.~+/=-]*\d)[\w.~+/=-]{20,})/dg },
|
|
1334
|
-
{ kind: "password", pattern:
|
|
1335
|
-
{ kind: "password", pattern:
|
|
1435
|
+
{ kind: "password", pattern: keyed(STRONG_NAME, `([^\\s"'&;,]{4,})`), skip: isProse },
|
|
1436
|
+
{ kind: "password", pattern: keyed(WEAK_NAME, `([^\\s"'&;,]{4,})`), skip: isWeak },
|
|
1437
|
+
{ kind: "password", pattern: keyed(STRONG_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isPlaceholder },
|
|
1438
|
+
{ kind: "password", pattern: keyed(WEAK_NAME, `(["'])((?:\\\\.|(?!\\1)[^\\\\\\n]){4,})\\1`), skip: isWeak }
|
|
1336
1439
|
];
|
|
1337
1440
|
var PEM_BEGIN = /-----BEGIN [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
1338
1441
|
var PEM_END = /-----END [A-Z ]*PRIVATE KEY(?: BLOCK)?-----/;
|
|
@@ -1437,7 +1540,7 @@ function findSecrets(line, known) {
|
|
|
1437
1540
|
if (start === undefined || end === undefined)
|
|
1438
1541
|
continue;
|
|
1439
1542
|
const value = line.slice(start, end);
|
|
1440
|
-
if (!skip?.(value))
|
|
1543
|
+
if (!skip?.(value, line.slice(0, start)))
|
|
1441
1544
|
found.push({ start, end, kind, mask: hint(value) });
|
|
1442
1545
|
}
|
|
1443
1546
|
}
|
|
@@ -1927,8 +2030,8 @@ var usage2 = `ev audit [dir...] [--fix]
|
|
|
1927
2030
|
|
|
1928
2031
|
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
2032
|
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
|
-
|
|
2033
|
+
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.`;
|
|
2034
|
+
var EXITS = [[0, "it finds none (with --fix, when none is left)"], [1, "it finds one"], [2, "a usage error"]];
|
|
1932
2035
|
var options = {
|
|
1933
2036
|
json: jsonOption("the findings and the folders it could not read"),
|
|
1934
2037
|
fix: { type: "boolean", description: "move inline compose secrets into a .env and shut other accounts out" }
|
|
@@ -1948,12 +2051,12 @@ async function isFolder(path) {
|
|
|
1948
2051
|
}
|
|
1949
2052
|
}
|
|
1950
2053
|
function shown2(path) {
|
|
1951
|
-
return path.startsWith(`${
|
|
2054
|
+
return path.startsWith(`${process16.cwd()}/`) ? relative(process16.cwd(), path) : path;
|
|
1952
2055
|
}
|
|
1953
2056
|
async function fixAll(exposed, json) {
|
|
1954
2057
|
const fixed = [];
|
|
1955
2058
|
let left = false;
|
|
1956
|
-
const tint = role("path",
|
|
2059
|
+
const tint = role("path", process16.stdout);
|
|
1957
2060
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
1958
2061
|
const fix = secrets === undefined ? undefined : await fixCompose(path, group === true);
|
|
1959
2062
|
const open = fix?.open ?? (readable && !await shutOthersOut(path, group === true) ? [path] : []);
|
|
@@ -1977,8 +2080,8 @@ async function fixAll(exposed, json) {
|
|
|
1977
2080
|
return { fixed, left };
|
|
1978
2081
|
}
|
|
1979
2082
|
async function audit2(args) {
|
|
1980
|
-
const parsed = parse(args, usage2, options);
|
|
1981
|
-
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) =>
|
|
2083
|
+
const parsed = parse(args, usage2, options, { exits: EXITS });
|
|
2084
|
+
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) => resolve4(dir));
|
|
1982
2085
|
for (const dir of roots) {
|
|
1983
2086
|
if (!await isFolder(dir))
|
|
1984
2087
|
fail(`${dir} is not a folder`);
|
|
@@ -2005,8 +2108,8 @@ async function audit2(args) {
|
|
|
2005
2108
|
console.log("no exposed .env file nor compose file writing a secret out");
|
|
2006
2109
|
return 0;
|
|
2007
2110
|
}
|
|
2008
|
-
const uid =
|
|
2009
|
-
const tint = role("path",
|
|
2111
|
+
const uid = process16.getuid?.();
|
|
2112
|
+
const tint = role("path", process16.stdout);
|
|
2010
2113
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
2011
2114
|
const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
|
|
2012
2115
|
const problems = [
|
|
@@ -2022,27 +2125,25 @@ async function audit2(args) {
|
|
|
2022
2125
|
}
|
|
2023
2126
|
|
|
2024
2127
|
// src/commands/compare.ts
|
|
2025
|
-
import
|
|
2128
|
+
import process17 from "process";
|
|
2026
2129
|
var diffUsage = `ev diff <a> <b>
|
|
2027
2130
|
|
|
2028
2131
|
Names the keys set in one file and not the other, never their values.
|
|
2029
2132
|
|
|
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.`;
|
|
2133
|
+
--json prints {a, b, onlyA, onlyB}.`;
|
|
2134
|
+
var DIFF_EXITS = [[0, "both set the same keys"], [1, "they differ"], [2, "a usage error"]];
|
|
2033
2135
|
var missingUsage = `ev missing [file]
|
|
2034
2136
|
|
|
2035
2137
|
Names the keys the reference file sets that the file (.env by default) does not.
|
|
2036
2138
|
|
|
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.`;
|
|
2139
|
+
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing.`;
|
|
2140
|
+
var MISSING_EXITS = [[0, "none is missing"], [1, "some are"], [2, "a usage error"]];
|
|
2040
2141
|
var jsonFlag = { json: jsonOption() };
|
|
2041
2142
|
async function keys(path) {
|
|
2042
2143
|
return new Set(entries(await readEnv(path)).keys());
|
|
2043
2144
|
}
|
|
2044
2145
|
async function diff(args) {
|
|
2045
|
-
const parsed = parse(args, diffUsage, jsonFlag);
|
|
2146
|
+
const parsed = parse(args, diffUsage, jsonFlag, { exits: DIFF_EXITS });
|
|
2046
2147
|
const [a, b] = parsed.positionals;
|
|
2047
2148
|
if (a === undefined || b === undefined)
|
|
2048
2149
|
fail(`needs two files
|
|
@@ -2056,8 +2157,8 @@ ${diffUsage}`);
|
|
|
2056
2157
|
printJson({ a, b, onlyA, onlyB });
|
|
2057
2158
|
return onlyA.length + onlyB.length === 0 ? 0 : 1;
|
|
2058
2159
|
}
|
|
2059
|
-
const path = role("path",
|
|
2060
|
-
const value = role("value",
|
|
2160
|
+
const path = role("path", process17.stdout);
|
|
2161
|
+
const value = role("value", process17.stdout);
|
|
2061
2162
|
const lines = [...onlyA.map((key) => `only in ${path(a)}: ${value(key)}`), ...onlyB.map((key) => `only in ${path(b)}: ${value(key)}`)];
|
|
2062
2163
|
if (lines.length === 0)
|
|
2063
2164
|
return 0;
|
|
@@ -2066,7 +2167,7 @@ ${diffUsage}`);
|
|
|
2066
2167
|
return 1;
|
|
2067
2168
|
}
|
|
2068
2169
|
async function missing(args) {
|
|
2069
|
-
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag });
|
|
2170
|
+
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag }, { exits: MISSING_EXITS });
|
|
2070
2171
|
const [file = ".env"] = parsed.positionals;
|
|
2071
2172
|
const against = parsed.values.against ?? ".env.example";
|
|
2072
2173
|
const have = await keys(file);
|
|
@@ -2078,8 +2179,8 @@ async function missing(args) {
|
|
|
2078
2179
|
}
|
|
2079
2180
|
if (absent.length === 0)
|
|
2080
2181
|
return 0;
|
|
2081
|
-
const path = role("path",
|
|
2082
|
-
const value = role("value",
|
|
2182
|
+
const path = role("path", process17.stdout);
|
|
2183
|
+
const value = role("value", process17.stdout);
|
|
2083
2184
|
console.log(absent.map((key) => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join(`
|
|
2084
2185
|
`));
|
|
2085
2186
|
return 1;
|
|
@@ -2092,24 +2193,20 @@ var KEY_NAME = /^[A-Z_][\w.-]*$/i;
|
|
|
2092
2193
|
var QUIET = { quiet: { type: "boolean", short: "q", description: "print nothing on success" } };
|
|
2093
2194
|
var setUsage = `ev set KEY [file] [--quiet]
|
|
2094
2195
|
|
|
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.`;
|
|
2196
|
+
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.`;
|
|
2197
|
+
var SET_EXITS = [[0, "it wrote the key"], [1, "it could not"], [2, "a usage error"]];
|
|
2098
2198
|
var unsetUsage = `ev unset KEY [file] [--quiet]
|
|
2099
2199
|
|
|
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.`;
|
|
2200
|
+
Removes every line setting KEY from the file (.env by default), leaving comments and other lines as they are.`;
|
|
2201
|
+
var UNSET_EXITS = [[0, "it removed the key"], [1, "the file does not set it"], [2, "a usage error"]];
|
|
2103
2202
|
var mvUsage = `ev mv KEY --from <file> --to <file> [--quiet]
|
|
2104
2203
|
|
|
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.`;
|
|
2204
|
+
Moves KEY's line from one file to another, as written. Refuses to replace a key the target already sets unless --force.`;
|
|
2205
|
+
var MV_EXITS = [[0, "it moved the key"], [1, "the source lacks it or the target already sets it"], [2, "a usage error"]];
|
|
2108
2206
|
var cpUsage = `ev cp KEY --from <file> --to <file> [--as NEWKEY] [--quiet]
|
|
2109
2207
|
|
|
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
|
-
Exits 0 when it copied the key, 1 when the source lacks it, 2 on a usage error.`;
|
|
2208
|
+
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.`;
|
|
2209
|
+
var CP_EXITS = [[0, "it copied the key"], [1, "the source lacks it"], [2, "a usage error"]];
|
|
2113
2210
|
async function readValue(from) {
|
|
2114
2211
|
const input = await readInput(from ?? "-", { noStdin: "pipe the value on stdin or give -F <file>, it is never taken from the command line" });
|
|
2115
2212
|
if (input === "")
|
|
@@ -2128,7 +2225,7 @@ async function set(args) {
|
|
|
2128
2225
|
file: { type: "string", short: "F", description: "read the value from this file instead of stdin" },
|
|
2129
2226
|
empty: { type: "boolean", description: "set an empty value, reading nothing" },
|
|
2130
2227
|
...QUIET
|
|
2131
|
-
});
|
|
2228
|
+
}, { exits: SET_EXITS });
|
|
2132
2229
|
const [key, target = DEFAULT_FILE] = parsed.positionals;
|
|
2133
2230
|
if (key === undefined)
|
|
2134
2231
|
fail(`missing KEY
|
|
@@ -2150,7 +2247,7 @@ ${setUsage}`);
|
|
|
2150
2247
|
return 0;
|
|
2151
2248
|
}
|
|
2152
2249
|
async function unset(args) {
|
|
2153
|
-
const parsed = parse(args, unsetUsage, QUIET);
|
|
2250
|
+
const parsed = parse(args, unsetUsage, QUIET, { exits: UNSET_EXITS });
|
|
2154
2251
|
const [key, target = DEFAULT_FILE] = parsed.positionals;
|
|
2155
2252
|
if (key === undefined)
|
|
2156
2253
|
fail(`missing KEY
|
|
@@ -2191,7 +2288,7 @@ async function mv(args) {
|
|
|
2191
2288
|
to: { type: "string", description: "the file to put KEY in, created when missing" },
|
|
2192
2289
|
force: { type: "boolean", description: "replace KEY when the target already sets it" },
|
|
2193
2290
|
...QUIET
|
|
2194
|
-
});
|
|
2291
|
+
}, { exits: MV_EXITS });
|
|
2195
2292
|
const [key] = parsed.positionals;
|
|
2196
2293
|
const { from, to, force } = parsed.values;
|
|
2197
2294
|
if (key === undefined || from === undefined || to === undefined)
|
|
@@ -2213,7 +2310,7 @@ async function cp(args) {
|
|
|
2213
2310
|
to: { type: "string", description: "the file to put the copy in, created when missing" },
|
|
2214
2311
|
as: { type: "string", description: "store the copy under this key instead" },
|
|
2215
2312
|
...QUIET
|
|
2216
|
-
});
|
|
2313
|
+
}, { exits: CP_EXITS });
|
|
2217
2314
|
const [key] = parsed.positionals;
|
|
2218
2315
|
const { from, to, as } = parsed.values;
|
|
2219
2316
|
if (key === undefined || from === undefined || to === undefined)
|
|
@@ -2229,7 +2326,7 @@ ${cpUsage}`);
|
|
|
2229
2326
|
|
|
2230
2327
|
// src/commands/pins.ts
|
|
2231
2328
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
2232
|
-
import { join as join10, resolve as
|
|
2329
|
+
import { join as join10, resolve as resolve5 } from "path";
|
|
2233
2330
|
|
|
2234
2331
|
// src/pins.ts
|
|
2235
2332
|
import { readdir as readdir3, readFile } from "fs/promises";
|
|
@@ -2412,8 +2509,8 @@ Checks that an app's tests pin the env that reaches outside.
|
|
|
2412
2509
|
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
2510
|
A file whose pages reach none of them says so with a \`// ev pins: none reached, <why>\` comment.
|
|
2414
2511
|
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
|
-
|
|
2512
|
+
Reads variable names only, never a value.`;
|
|
2513
|
+
var EXITS2 = [[0, "everything is pinned"], [1, "something is not"], [2, "a usage error"]];
|
|
2417
2514
|
var options2 = {
|
|
2418
2515
|
json: jsonOption("each app with its reaching, unpinned variables and flagged test files"),
|
|
2419
2516
|
except: { type: "string", description: "comma-separated variables to leave out, as ones that only link back to the app" }
|
|
@@ -2446,9 +2543,9 @@ function name(app, root) {
|
|
|
2446
2543
|
return app.app === root ? app.app.split("/").at(-1) ?? app.app : app.app.slice(root.length + 1);
|
|
2447
2544
|
}
|
|
2448
2545
|
async function pins(args) {
|
|
2449
|
-
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"] });
|
|
2546
|
+
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"], exits: EXITS2 });
|
|
2450
2547
|
const json = parsed.values.json === true;
|
|
2451
|
-
const root =
|
|
2548
|
+
const root = resolve5(parsed.positionals[0] ?? ".");
|
|
2452
2549
|
const except = new Set((parsed.values.except ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== ""));
|
|
2453
2550
|
if (!await isFolder2(root))
|
|
2454
2551
|
fail(`${root} is not a folder`);
|
|
@@ -2480,16 +2577,14 @@ var listUsage = `ev list [file]
|
|
|
2480
2577
|
|
|
2481
2578
|
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
2579
|
|
|
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.`;
|
|
2580
|
+
--json prints [{file, key, value, secret}], value masked and secret true when a value was.`;
|
|
2581
|
+
var LIST_EXITS = [[0, "it printed them"], [1, "there is no .env* file"], [2, "a usage error"]];
|
|
2486
2582
|
var getUsage = `ev get KEY [file]
|
|
2487
2583
|
|
|
2488
2584
|
Prints the masked value of one key, from every .env* file that sets it or from one file.
|
|
2489
2585
|
|
|
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.`;
|
|
2586
|
+
--json prints [{file, key, value, secret}] for each file that sets it.`;
|
|
2587
|
+
var GET_EXITS = [[0, "the key is set"], [1, "it is not set anywhere"], [2, "a usage error"]];
|
|
2493
2588
|
function display(key, value, known) {
|
|
2494
2589
|
return maskValue(key, value, known).replaceAll(`
|
|
2495
2590
|
`, "\\n").replaceAll("\r", "\\r");
|
|
@@ -2522,7 +2617,7 @@ async function readAll(names) {
|
|
|
2522
2617
|
return { files, known: await loadKnown(process.cwd(), files.map(([, file]) => file)) };
|
|
2523
2618
|
}
|
|
2524
2619
|
async function list(args) {
|
|
2525
|
-
const parsed = parse(args, listUsage, jsonFlag2);
|
|
2620
|
+
const parsed = parse(args, listUsage, jsonFlag2, { exits: LIST_EXITS });
|
|
2526
2621
|
const [file] = parsed.positionals;
|
|
2527
2622
|
const names = file === undefined ? await envFiles() : [file];
|
|
2528
2623
|
if (names.length === 0)
|
|
@@ -2540,7 +2635,7 @@ async function list(args) {
|
|
|
2540
2635
|
return 0;
|
|
2541
2636
|
}
|
|
2542
2637
|
async function get(args) {
|
|
2543
|
-
const parsed = parse(args, getUsage, jsonFlag2);
|
|
2638
|
+
const parsed = parse(args, getUsage, jsonFlag2, { exits: GET_EXITS });
|
|
2544
2639
|
const [key, file] = parsed.positionals;
|
|
2545
2640
|
if (key === undefined)
|
|
2546
2641
|
fail(`missing KEY
|
|
@@ -2563,19 +2658,17 @@ var grepUsage = `ev grep [-i] <regex> [file...]
|
|
|
2563
2658
|
|
|
2564
2659
|
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
2660
|
|
|
2566
|
-
--json prints [{file, key, value, secret}]
|
|
2567
|
-
|
|
2568
|
-
Exits 0 when a key matches, 1 when none does, 2 on a usage error.`;
|
|
2661
|
+
--json prints [{file, key, value, secret}].`;
|
|
2662
|
+
var GREP_EXITS = [[0, "a key matches"], [1, "none does"], [2, "a usage error"]];
|
|
2569
2663
|
var showUsage = `ev show <rev>:<file>
|
|
2570
2664
|
|
|
2571
2665
|
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
2666
|
|
|
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.`;
|
|
2667
|
+
--json prints [{file, key, value, secret}].`;
|
|
2668
|
+
var SHOW_EXITS = [[0, "it printed them"], [1, "git cannot show the file"], [2, "a usage error"]];
|
|
2576
2669
|
var REVISION = /^([^:]+):(.+)$/;
|
|
2577
2670
|
async function grep(args) {
|
|
2578
|
-
const parsed = parse(args, grepUsage, { "ignore-case": { type: "boolean", short: "i", description: "match the key whatever its case" }, ...jsonFlag2 });
|
|
2671
|
+
const parsed = parse(args, grepUsage, { "ignore-case": { type: "boolean", short: "i", description: "match the key whatever its case" }, ...jsonFlag2 }, { exits: GREP_EXITS });
|
|
2579
2672
|
const [source, ...given] = parsed.positionals;
|
|
2580
2673
|
if (source === undefined)
|
|
2581
2674
|
fail(`missing the regex
|
|
@@ -2602,7 +2695,7 @@ ${grepUsage}`);
|
|
|
2602
2695
|
return 0;
|
|
2603
2696
|
}
|
|
2604
2697
|
async function show(args) {
|
|
2605
|
-
const parsed = parse(args, showUsage, jsonFlag2);
|
|
2698
|
+
const parsed = parse(args, showUsage, jsonFlag2, { exits: SHOW_EXITS });
|
|
2606
2699
|
const [target] = parsed.positionals;
|
|
2607
2700
|
const [, revision, path] = REVISION.exec(target ?? "") ?? [];
|
|
2608
2701
|
if (revision === undefined || path === undefined)
|
|
@@ -2625,7 +2718,7 @@ ${showUsage}`);
|
|
|
2625
2718
|
}
|
|
2626
2719
|
|
|
2627
2720
|
// src/commands/redact.ts
|
|
2628
|
-
import
|
|
2721
|
+
import process18 from "process";
|
|
2629
2722
|
|
|
2630
2723
|
// src/redactor.ts
|
|
2631
2724
|
var DIFF_START = /^(?:diff --git |@@ )/;
|
|
@@ -2746,15 +2839,14 @@ function check(text, known) {
|
|
|
2746
2839
|
var usage4 = `redact [--check]
|
|
2747
2840
|
|
|
2748
2841
|
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.`;
|
|
2842
|
+
--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\`.`;
|
|
2843
|
+
var EXITS3 = [[0, "it copied the input or found no secret"], [1, "--check finds one"], [2, "a usage error"]];
|
|
2752
2844
|
var options3 = {
|
|
2753
2845
|
check: { type: "boolean", description: "list where secrets are instead of masking them, exit 1 when found" },
|
|
2754
2846
|
"no-env": { type: "boolean", description: "do not search for the values of the .env* files" }
|
|
2755
2847
|
};
|
|
2756
2848
|
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"]] });
|
|
2849
|
+
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
2850
|
const known = parsed.values["no-env"] === true ? undefined : await loadKnown();
|
|
2759
2851
|
if (parsed.values.check === true) {
|
|
2760
2852
|
const findings = check(await readInput("-"), known);
|
|
@@ -2765,13 +2857,13 @@ async function redact(args) {
|
|
|
2765
2857
|
const redactor = new Redactor(known);
|
|
2766
2858
|
const decoder = new TextDecoder;
|
|
2767
2859
|
for await (const chunk of Bun.stdin.stream())
|
|
2768
|
-
|
|
2769
|
-
|
|
2860
|
+
process18.stdout.write(redactor.push(decoder.decode(chunk, { stream: true })));
|
|
2861
|
+
process18.stdout.write(redactor.push(decoder.decode()) + redactor.end());
|
|
2770
2862
|
return 0;
|
|
2771
2863
|
}
|
|
2772
2864
|
|
|
2773
2865
|
// src/ev.ts
|
|
2774
|
-
|
|
2866
|
+
process19.exitCode = await runCli({
|
|
2775
2867
|
name: "ev",
|
|
2776
2868
|
about: ".env files listed and edited with secrets masked",
|
|
2777
2869
|
replaces: "cat .env, grep on env files and editing them by hand",
|