@kaynooo/cli-env 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/ev.js +175 -127
- package/dist/redact.js +104 -53
- package/package.json +2 -2
- package/src/commands/audit.ts +8 -6
- package/src/commands/compare.ts +7 -6
- package/src/commands/edit.ts +30 -21
- package/src/commands/pins.ts +5 -3
- package/src/commands/read.ts +13 -12
- package/src/commands/redact.ts +5 -2
- package/src/files.ts +2 -2
package/dist/ev.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ev.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
11
|
import process7 from "process";
|
|
12
|
+
|
|
12
13
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
13
14
|
var N = new Map;
|
|
14
15
|
var Nt = /\s+\S*$/;
|
|
@@ -26,6 +27,7 @@ function ko(t, e, r = "...") {
|
|
|
26
27
|
}
|
|
27
28
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
28
29
|
var z = new Map;
|
|
30
|
+
|
|
29
31
|
// ../kit/src/mode.ts
|
|
30
32
|
import process2 from "process";
|
|
31
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -71,7 +73,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
71
73
|
return false;
|
|
72
74
|
return r?.isTTY === true;
|
|
73
75
|
}
|
|
74
|
-
function
|
|
76
|
+
function f(r, e = []) {
|
|
75
77
|
let l = "", n = "";
|
|
76
78
|
for (let t = 0, i = e.length;t < i; t++)
|
|
77
79
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -81,7 +83,7 @@ function f2(r, e = []) {
|
|
|
81
83
|
if (Array.isArray(a)) {
|
|
82
84
|
let s = g.get(i);
|
|
83
85
|
if (s === undefined)
|
|
84
|
-
s =
|
|
86
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
85
87
|
return s;
|
|
86
88
|
}
|
|
87
89
|
if (typeof a === "function")
|
|
@@ -90,20 +92,20 @@ function f2(r, e = []) {
|
|
|
90
92
|
if (u === undefined) {
|
|
91
93
|
if (g.size >= 64)
|
|
92
94
|
g.clear();
|
|
93
|
-
u =
|
|
95
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
94
96
|
}
|
|
95
97
|
return u;
|
|
96
98
|
};
|
|
97
99
|
throw Error(`Unknown style: ${String(i)}`);
|
|
98
100
|
} });
|
|
99
101
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
102
|
+
function Fe(r = {}) {
|
|
103
|
+
return f(r);
|
|
102
104
|
}
|
|
103
|
-
var
|
|
105
|
+
var o = Fe();
|
|
104
106
|
|
|
105
107
|
// ../kit/src/theme.ts
|
|
106
|
-
import { existsSync as
|
|
108
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
107
109
|
import { homedir as homedir2 } from "os";
|
|
108
110
|
import { join as join3, resolve as resolve2 } from "path";
|
|
109
111
|
import process5 from "process";
|
|
@@ -124,6 +126,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
// ../kit/src/user-config.ts
|
|
129
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
127
130
|
import { homedir } from "os";
|
|
128
131
|
import { join as join2 } from "path";
|
|
129
132
|
import process4 from "process";
|
|
@@ -134,6 +137,24 @@ function configBase(where = {}) {
|
|
|
134
137
|
function userConfigPath(bin, where = {}) {
|
|
135
138
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
136
139
|
}
|
|
140
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
141
|
+
const current = userConfigPath(bin, where);
|
|
142
|
+
if (existsSync2(current))
|
|
143
|
+
return current;
|
|
144
|
+
const base = configBase(where);
|
|
145
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
146
|
+
}
|
|
147
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
148
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
149
|
+
if (!existsSync2(path))
|
|
150
|
+
return {};
|
|
151
|
+
try {
|
|
152
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
153
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
154
|
+
} catch {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
137
158
|
|
|
138
159
|
// ../kit/src/theme.ts
|
|
139
160
|
var ENDS = new Map;
|
|
@@ -200,7 +221,7 @@ function readThemeFile(path, warn) {
|
|
|
200
221
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
201
222
|
return;
|
|
202
223
|
}
|
|
203
|
-
const parsed = JSON.parse(
|
|
224
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
204
225
|
if (isRecord(parsed))
|
|
205
226
|
return parsed;
|
|
206
227
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -266,7 +287,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
289
|
function endsWalk(home) {
|
|
269
|
-
return (dir) => dir === resolve2(home) ||
|
|
290
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
270
291
|
}
|
|
271
292
|
var warned = new Set;
|
|
272
293
|
function warnOnce(message) {
|
|
@@ -322,7 +343,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
322
343
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
323
344
|
}
|
|
324
345
|
function paint(stream, env = process6.env) {
|
|
325
|
-
return
|
|
346
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
326
347
|
}
|
|
327
348
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
328
349
|
const colors = paint(stream, env);
|
|
@@ -336,6 +357,9 @@ function marked(mark, text, stream, detail, env = process6.env) {
|
|
|
336
357
|
function ok(text, detail) {
|
|
337
358
|
console.log(marked("ok", text, process6.stdout, detail));
|
|
338
359
|
}
|
|
360
|
+
function warn(text, detail) {
|
|
361
|
+
console.error(marked("warn", text, process6.stderr, detail));
|
|
362
|
+
}
|
|
339
363
|
function role(name, stream, env = process6.env) {
|
|
340
364
|
const colors = paint(stream, env);
|
|
341
365
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
@@ -416,18 +440,14 @@ var FULL_STOP = /\.$/;
|
|
|
416
440
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
417
441
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
418
442
|
}
|
|
419
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
420
|
-
return [usageLine(usage, colors),
|
|
443
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
444
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
421
445
|
`);
|
|
422
446
|
}
|
|
423
447
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
424
448
|
if (exits.length === 0)
|
|
425
449
|
return [];
|
|
426
|
-
|
|
427
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
428
|
-
}
|
|
429
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
430
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
450
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
431
451
|
}
|
|
432
452
|
function wantsHelpJson(env = process8.env) {
|
|
433
453
|
return env.KIT_HELP === "json";
|
|
@@ -715,21 +735,45 @@ function nearestOption(message, options, allowNegative) {
|
|
|
715
735
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
716
736
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
717
737
|
}
|
|
738
|
+
// ../kit/src/argv.ts
|
|
739
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
740
|
+
import { resolve as resolve3 } from "path";
|
|
741
|
+
import process11 from "process";
|
|
742
|
+
function commandLine() {
|
|
743
|
+
try {
|
|
744
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
745
|
+
} catch {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function realPath(word) {
|
|
750
|
+
try {
|
|
751
|
+
return realpathSync(resolve3(word));
|
|
752
|
+
} catch {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
757
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
758
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
759
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
760
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
761
|
+
}
|
|
718
762
|
// ../kit/src/progress.ts
|
|
719
763
|
var ESC = String.fromCharCode(27);
|
|
720
764
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
721
765
|
var RESET_STYLE = `${ESC}[0m`;
|
|
722
766
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
723
767
|
// ../kit/src/cli.ts
|
|
724
|
-
import { readFileSync as
|
|
768
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
725
769
|
import { dirname as dirname3, join as join5 } from "path";
|
|
726
|
-
import
|
|
770
|
+
import process13 from "process";
|
|
727
771
|
|
|
728
772
|
// ../kit/src/usage.ts
|
|
729
773
|
import { appendFileSync, mkdirSync } from "fs";
|
|
730
774
|
import { homedir as homedir3 } from "os";
|
|
731
775
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
732
|
-
import
|
|
776
|
+
import process12 from "process";
|
|
733
777
|
|
|
734
778
|
// ../kit/src/logs.ts
|
|
735
779
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -743,14 +787,14 @@ var usageError;
|
|
|
743
787
|
function noteUsageError(message) {
|
|
744
788
|
usageError = message;
|
|
745
789
|
}
|
|
746
|
-
function stateHome(env =
|
|
790
|
+
function stateHome(env = process12.env) {
|
|
747
791
|
const dir = env.XDG_STATE_HOME;
|
|
748
792
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
749
793
|
}
|
|
750
|
-
function usagePath(env =
|
|
794
|
+
function usagePath(env = process12.env) {
|
|
751
795
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
752
796
|
}
|
|
753
|
-
function usageRecorded(env =
|
|
797
|
+
function usageRecorded(env = process12.env) {
|
|
754
798
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
755
799
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
756
800
|
}
|
|
@@ -764,7 +808,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
764
808
|
usageError = undefined;
|
|
765
809
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
766
810
|
}
|
|
767
|
-
function recordUsage(entry, env =
|
|
811
|
+
function recordUsage(entry, env = process12.env) {
|
|
768
812
|
if (!usageRecorded(env))
|
|
769
813
|
return;
|
|
770
814
|
try {
|
|
@@ -841,7 +885,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
841
885
|
header(colors, summary),
|
|
842
886
|
"",
|
|
843
887
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
844
|
-
...replacesRows(replaces, colors),
|
|
845
888
|
"",
|
|
846
889
|
...await commandRows(commands, colors),
|
|
847
890
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -855,8 +898,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
855
898
|
`);
|
|
856
899
|
}
|
|
857
900
|
function printError(prefix, message, hint, cause) {
|
|
858
|
-
const colors = paint(
|
|
859
|
-
const styled = takesControlCodes(
|
|
901
|
+
const colors = paint(process13.stderr);
|
|
902
|
+
const styled = takesControlCodes(process13.stderr);
|
|
860
903
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
861
904
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
862
905
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -899,11 +942,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
899
942
|
}
|
|
900
943
|
}
|
|
901
944
|
if (name === undefined && level.path.length > 1) {
|
|
902
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
945
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
903
946
|
return 2;
|
|
904
947
|
}
|
|
905
948
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
906
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
949
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
907
950
|
return 0;
|
|
908
951
|
}
|
|
909
952
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -959,24 +1002,24 @@ function candidateLine(candidate) {
|
|
|
959
1002
|
}
|
|
960
1003
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
961
1004
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
962
|
-
|
|
1005
|
+
const typed = [];
|
|
963
1006
|
let at = 0;
|
|
964
1007
|
while (at < before.length) {
|
|
965
1008
|
const word = before[at];
|
|
966
1009
|
if (word === "--") {
|
|
967
|
-
|
|
1010
|
+
typed.push(...before.slice(at + 1));
|
|
968
1011
|
break;
|
|
969
1012
|
}
|
|
970
1013
|
if (!word.startsWith("-"))
|
|
971
|
-
|
|
1014
|
+
typed.push(word);
|
|
972
1015
|
else if (takesValue(word))
|
|
973
1016
|
at++;
|
|
974
1017
|
at++;
|
|
975
1018
|
}
|
|
976
1019
|
const last = positionals.at(-1);
|
|
977
|
-
if (
|
|
978
|
-
return positionals[
|
|
979
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1020
|
+
if (typed.length < positionals.length)
|
|
1021
|
+
return { name: positionals[typed.length], typed };
|
|
1022
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
980
1023
|
}
|
|
981
1024
|
async function leafCandidates(run, words) {
|
|
982
1025
|
const completing = await completingOf(run);
|
|
@@ -984,12 +1027,12 @@ async function leafCandidates(run, words) {
|
|
|
984
1027
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
985
1028
|
const flag = words.at(-2);
|
|
986
1029
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1030
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
987
1031
|
if (option?.type === "string") {
|
|
988
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1032
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
989
1033
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
990
1034
|
}
|
|
991
|
-
const
|
|
992
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1035
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
993
1036
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
994
1037
|
}
|
|
995
1038
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1020,9 +1063,13 @@ async function printCandidates(found) {
|
|
|
1020
1063
|
return 0;
|
|
1021
1064
|
}
|
|
1022
1065
|
function packageVersion(entry = Bun.main) {
|
|
1023
|
-
|
|
1066
|
+
let resolved = entry;
|
|
1067
|
+
try {
|
|
1068
|
+
resolved = realpathSync2(entry);
|
|
1069
|
+
} catch {}
|
|
1070
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1024
1071
|
try {
|
|
1025
|
-
const { version } = JSON.parse(
|
|
1072
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1026
1073
|
if (typeof version === "string")
|
|
1027
1074
|
return version;
|
|
1028
1075
|
} catch {}
|
|
@@ -1030,7 +1077,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1030
1077
|
return "0.0.0";
|
|
1031
1078
|
}
|
|
1032
1079
|
}
|
|
1033
|
-
async function runCli(cli, argv =
|
|
1080
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1034
1081
|
const version = cli.version ?? packageVersion();
|
|
1035
1082
|
if (argv[0] === COMPLETE)
|
|
1036
1083
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1057,7 +1104,7 @@ function commandPath(scope, argv) {
|
|
|
1057
1104
|
}
|
|
1058
1105
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1059
1106
|
}
|
|
1060
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1107
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1061
1108
|
if (argv[0] === COMPLETE)
|
|
1062
1109
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1063
1110
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1080,7 +1127,7 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
|
|
|
1080
1127
|
// ../kit/src/compose.ts
|
|
1081
1128
|
async function captureOutput(argv, { cwd, env } = {}) {
|
|
1082
1129
|
const run = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, env: { ...process.env, ...env }, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
|
|
1083
|
-
const [stdout, stderr, code] = await Promise.all([run.stdout.text(), run.stderr.text(), run.exited]);
|
|
1130
|
+
const [stdout, stderr, code] = await Promise.all([new Response(run.stdout).text(), new Response(run.stderr).text(), run.exited]);
|
|
1084
1131
|
return { code, stdout, stderr };
|
|
1085
1132
|
}
|
|
1086
1133
|
async function compose(args, { flags = [], ...options } = {}) {
|
|
@@ -1088,6 +1135,11 @@ async function compose(args, { flags = [], ...options } = {}) {
|
|
|
1088
1135
|
}
|
|
1089
1136
|
// ../kit/src/folders.ts
|
|
1090
1137
|
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1138
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
1139
|
+
const configured = readUserConfig("config", where).ignore;
|
|
1140
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1141
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1142
|
+
}
|
|
1091
1143
|
// ../kit/src/secrets.ts
|
|
1092
1144
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1093
1145
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1101,8 +1153,8 @@ var SESSION_FILES = new Glob("*.json");
|
|
|
1101
1153
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1102
1154
|
// src/commands/audit.ts
|
|
1103
1155
|
import { stat as stat4 } from "fs/promises";
|
|
1104
|
-
import { relative, resolve as
|
|
1105
|
-
import
|
|
1156
|
+
import { relative, resolve as resolve4 } from "path";
|
|
1157
|
+
import process15 from "process";
|
|
1106
1158
|
|
|
1107
1159
|
// ../kit/src/shell.ts
|
|
1108
1160
|
var SEPARATORS = new Set([`
|
|
@@ -1451,7 +1503,7 @@ function maskValue(key, value, known) {
|
|
|
1451
1503
|
var ENV_FILE = /^(?:\.env(?:\..+)?|.+\.env|\.envrc)$/;
|
|
1452
1504
|
var TEMPLATE = /\.(?:example|sample|template|dist|defaults)$/;
|
|
1453
1505
|
var KNOWN_DEPTH = 3;
|
|
1454
|
-
var SKIPPED =
|
|
1506
|
+
var SKIPPED = ignoredFolders([".git", ".kay"]);
|
|
1455
1507
|
var LOCK_WAIT_MS = 5000;
|
|
1456
1508
|
var LOCK_STALE_MS = 30000;
|
|
1457
1509
|
var REAP_STALE_MS = 5000;
|
|
@@ -1898,8 +1950,8 @@ var usage2 = `ev audit [dir...] [--fix]
|
|
|
1898
1950
|
|
|
1899
1951
|
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.
|
|
1900
1952
|
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.
|
|
1901
|
-
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
|
|
1902
|
-
|
|
1953
|
+
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.`;
|
|
1954
|
+
var EXITS = [[0, "it finds none (with --fix, when none is left)"], [1, "it finds one"], [2, "a usage error"]];
|
|
1903
1955
|
var options = {
|
|
1904
1956
|
json: jsonOption("the findings and the folders it could not read"),
|
|
1905
1957
|
fix: { type: "boolean", description: "move inline compose secrets into a .env and shut other accounts out" }
|
|
@@ -1919,12 +1971,12 @@ async function isFolder(path) {
|
|
|
1919
1971
|
}
|
|
1920
1972
|
}
|
|
1921
1973
|
function shown2(path) {
|
|
1922
|
-
return path.startsWith(`${
|
|
1974
|
+
return path.startsWith(`${process15.cwd()}/`) ? relative(process15.cwd(), path) : path;
|
|
1923
1975
|
}
|
|
1924
1976
|
async function fixAll(exposed, json) {
|
|
1925
1977
|
const fixed = [];
|
|
1926
1978
|
let left = false;
|
|
1927
|
-
const tint = role("path",
|
|
1979
|
+
const tint = role("path", process15.stdout);
|
|
1928
1980
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
1929
1981
|
const fix = secrets === undefined ? undefined : await fixCompose(path, group === true);
|
|
1930
1982
|
const open = fix?.open ?? (readable && !await shutOthersOut(path, group === true) ? [path] : []);
|
|
@@ -1948,8 +2000,8 @@ async function fixAll(exposed, json) {
|
|
|
1948
2000
|
return { fixed, left };
|
|
1949
2001
|
}
|
|
1950
2002
|
async function audit2(args) {
|
|
1951
|
-
const parsed = parse(args, usage2, options);
|
|
1952
|
-
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) =>
|
|
2003
|
+
const parsed = parse(args, usage2, options, { exits: EXITS });
|
|
2004
|
+
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) => resolve4(dir));
|
|
1953
2005
|
for (const dir of roots) {
|
|
1954
2006
|
if (!await isFolder(dir))
|
|
1955
2007
|
fail(`${dir} is not a folder`);
|
|
@@ -1957,10 +2009,10 @@ async function audit2(args) {
|
|
|
1957
2009
|
const { exposed, unread } = await audit(roots);
|
|
1958
2010
|
const json = parsed.values.json === true;
|
|
1959
2011
|
if (!json && unread.length > MAX_UNREAD_LISTED) {
|
|
1960
|
-
|
|
2012
|
+
warn(`could not read ${unread.length} folders, so they were not audited (--json lists them)`);
|
|
1961
2013
|
} else if (!json) {
|
|
1962
2014
|
for (const dir of unread)
|
|
1963
|
-
|
|
2015
|
+
warn(`could not read ${dir}, so it was not audited`);
|
|
1964
2016
|
}
|
|
1965
2017
|
if (parsed.values.fix === true && (json || exposed.length > 0)) {
|
|
1966
2018
|
const { fixed, left } = await fixAll(exposed, json);
|
|
@@ -1976,8 +2028,8 @@ async function audit2(args) {
|
|
|
1976
2028
|
console.log("no exposed .env file nor compose file writing a secret out");
|
|
1977
2029
|
return 0;
|
|
1978
2030
|
}
|
|
1979
|
-
const uid =
|
|
1980
|
-
const tint = role("path",
|
|
2031
|
+
const uid = process15.getuid?.();
|
|
2032
|
+
const tint = role("path", process15.stdout);
|
|
1981
2033
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
1982
2034
|
const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
|
|
1983
2035
|
const problems = [
|
|
@@ -1993,27 +2045,25 @@ async function audit2(args) {
|
|
|
1993
2045
|
}
|
|
1994
2046
|
|
|
1995
2047
|
// src/commands/compare.ts
|
|
1996
|
-
import
|
|
2048
|
+
import process16 from "process";
|
|
1997
2049
|
var diffUsage = `ev diff <a> <b>
|
|
1998
2050
|
|
|
1999
2051
|
Names the keys set in one file and not the other, never their values.
|
|
2000
2052
|
|
|
2001
|
-
--json prints {a, b, onlyA, onlyB}
|
|
2002
|
-
|
|
2003
|
-
Exits 0 when both set the same keys, 1 when they differ, 2 on a usage error.`;
|
|
2053
|
+
--json prints {a, b, onlyA, onlyB}.`;
|
|
2054
|
+
var DIFF_EXITS = [[0, "both set the same keys"], [1, "they differ"], [2, "a usage error"]];
|
|
2004
2055
|
var missingUsage = `ev missing [file]
|
|
2005
2056
|
|
|
2006
2057
|
Names the keys the reference file sets that the file (.env by default) does not.
|
|
2007
2058
|
|
|
2008
|
-
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing
|
|
2009
|
-
|
|
2010
|
-
Exits 0 when none is missing, 1 when some are, 2 on a usage error.`;
|
|
2059
|
+
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing.`;
|
|
2060
|
+
var MISSING_EXITS = [[0, "none is missing"], [1, "some are"], [2, "a usage error"]];
|
|
2011
2061
|
var jsonFlag = { json: jsonOption() };
|
|
2012
2062
|
async function keys(path) {
|
|
2013
2063
|
return new Set(entries(await readEnv(path)).keys());
|
|
2014
2064
|
}
|
|
2015
2065
|
async function diff(args) {
|
|
2016
|
-
const parsed = parse(args, diffUsage, jsonFlag);
|
|
2066
|
+
const parsed = parse(args, diffUsage, jsonFlag, { exits: DIFF_EXITS });
|
|
2017
2067
|
const [a, b] = parsed.positionals;
|
|
2018
2068
|
if (a === undefined || b === undefined)
|
|
2019
2069
|
fail(`needs two files
|
|
@@ -2027,8 +2077,8 @@ ${diffUsage}`);
|
|
|
2027
2077
|
printJson({ a, b, onlyA, onlyB });
|
|
2028
2078
|
return onlyA.length + onlyB.length === 0 ? 0 : 1;
|
|
2029
2079
|
}
|
|
2030
|
-
const path = role("path",
|
|
2031
|
-
const value = role("value",
|
|
2080
|
+
const path = role("path", process16.stdout);
|
|
2081
|
+
const value = role("value", process16.stdout);
|
|
2032
2082
|
const lines = [...onlyA.map((key) => `only in ${path(a)}: ${value(key)}`), ...onlyB.map((key) => `only in ${path(b)}: ${value(key)}`)];
|
|
2033
2083
|
if (lines.length === 0)
|
|
2034
2084
|
return 0;
|
|
@@ -2037,7 +2087,7 @@ ${diffUsage}`);
|
|
|
2037
2087
|
return 1;
|
|
2038
2088
|
}
|
|
2039
2089
|
async function missing(args) {
|
|
2040
|
-
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag });
|
|
2090
|
+
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag }, { exits: MISSING_EXITS });
|
|
2041
2091
|
const [file = ".env"] = parsed.positionals;
|
|
2042
2092
|
const against = parsed.values.against ?? ".env.example";
|
|
2043
2093
|
const have = await keys(file);
|
|
@@ -2049,8 +2099,8 @@ async function missing(args) {
|
|
|
2049
2099
|
}
|
|
2050
2100
|
if (absent.length === 0)
|
|
2051
2101
|
return 0;
|
|
2052
|
-
const path = role("path",
|
|
2053
|
-
const value = role("value",
|
|
2102
|
+
const path = role("path", process16.stdout);
|
|
2103
|
+
const value = role("value", process16.stdout);
|
|
2054
2104
|
console.log(absent.map((key) => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join(`
|
|
2055
2105
|
`));
|
|
2056
2106
|
return 1;
|
|
@@ -2060,26 +2110,23 @@ async function missing(args) {
|
|
|
2060
2110
|
var DEFAULT_FILE = ".env";
|
|
2061
2111
|
var TRAILING_NEWLINE = /\r?\n$/;
|
|
2062
2112
|
var KEY_NAME = /^[A-Z_][\w.-]*$/i;
|
|
2063
|
-
var
|
|
2064
|
-
|
|
2065
|
-
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.
|
|
2066
|
-
|
|
2067
|
-
Exits 0 when it wrote the key, 1 when it could not, 2 on a usage error.`;
|
|
2068
|
-
var unsetUsage = `ev unset KEY [file]
|
|
2113
|
+
var QUIET = { quiet: { type: "boolean", short: "q", description: "print nothing on success" } };
|
|
2114
|
+
var setUsage = `ev set KEY [file] [--quiet]
|
|
2069
2115
|
|
|
2070
|
-
|
|
2116
|
+
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.`;
|
|
2117
|
+
var SET_EXITS = [[0, "it wrote the key"], [1, "it could not"], [2, "a usage error"]];
|
|
2118
|
+
var unsetUsage = `ev unset KEY [file] [--quiet]
|
|
2071
2119
|
|
|
2072
|
-
|
|
2073
|
-
var
|
|
2120
|
+
Removes every line setting KEY from the file (.env by default), leaving comments and other lines as they are.`;
|
|
2121
|
+
var UNSET_EXITS = [[0, "it removed the key"], [1, "the file does not set it"], [2, "a usage error"]];
|
|
2122
|
+
var mvUsage = `ev mv KEY --from <file> --to <file> [--quiet]
|
|
2074
2123
|
|
|
2075
|
-
Moves KEY's line from one file to another, as written. Refuses to replace a key the target already sets unless --force
|
|
2124
|
+
Moves KEY's line from one file to another, as written. Refuses to replace a key the target already sets unless --force.`;
|
|
2125
|
+
var MV_EXITS = [[0, "it moved the key"], [1, "the source lacks it or the target already sets it"], [2, "a usage error"]];
|
|
2126
|
+
var cpUsage = `ev cp KEY --from <file> --to <file> [--as NEWKEY] [--quiet]
|
|
2076
2127
|
|
|
2077
|
-
|
|
2078
|
-
var
|
|
2079
|
-
|
|
2080
|
-
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.
|
|
2081
|
-
|
|
2082
|
-
Exits 0 when it copied the key, 1 when the source lacks it, 2 on a usage error.`;
|
|
2128
|
+
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.`;
|
|
2129
|
+
var CP_EXITS = [[0, "it copied the key"], [1, "the source lacks it"], [2, "a usage error"]];
|
|
2083
2130
|
async function readValue(from) {
|
|
2084
2131
|
const input = await readInput(from ?? "-", { noStdin: "pipe the value on stdin or give -F <file>, it is never taken from the command line" });
|
|
2085
2132
|
if (input === "")
|
|
@@ -2096,8 +2143,9 @@ async function readOrEmpty(path) {
|
|
|
2096
2143
|
async function set(args) {
|
|
2097
2144
|
const parsed = parse(args, setUsage, {
|
|
2098
2145
|
file: { type: "string", short: "F", description: "read the value from this file instead of stdin" },
|
|
2099
|
-
empty: { type: "boolean", description: "set an empty value, reading nothing" }
|
|
2100
|
-
|
|
2146
|
+
empty: { type: "boolean", description: "set an empty value, reading nothing" },
|
|
2147
|
+
...QUIET
|
|
2148
|
+
}, { exits: SET_EXITS });
|
|
2101
2149
|
const [key, target = DEFAULT_FILE] = parsed.positionals;
|
|
2102
2150
|
if (key === undefined)
|
|
2103
2151
|
fail(`missing KEY
|
|
@@ -2113,12 +2161,13 @@ ${setUsage}`);
|
|
|
2113
2161
|
await writeEnv(target, current);
|
|
2114
2162
|
return current;
|
|
2115
2163
|
});
|
|
2116
|
-
|
|
2164
|
+
if (parsed.values.quiet !== true)
|
|
2165
|
+
console.log(`${target}: ${key}=${maskValue(key, value, await loadKnown(process.cwd(), [file])).replaceAll(`
|
|
2117
2166
|
`, "\\n")}`);
|
|
2118
2167
|
return 0;
|
|
2119
2168
|
}
|
|
2120
2169
|
async function unset(args) {
|
|
2121
|
-
const parsed = parse(args, unsetUsage, {});
|
|
2170
|
+
const parsed = parse(args, unsetUsage, QUIET, { exits: UNSET_EXITS });
|
|
2122
2171
|
const [key, target = DEFAULT_FILE] = parsed.positionals;
|
|
2123
2172
|
if (key === undefined)
|
|
2124
2173
|
fail(`missing KEY
|
|
@@ -2130,7 +2179,8 @@ ${unsetUsage}`);
|
|
|
2130
2179
|
fail(`${key} is not set in ${target}`, 1);
|
|
2131
2180
|
await writeEnv(target, file);
|
|
2132
2181
|
});
|
|
2133
|
-
|
|
2182
|
+
if (parsed.values.quiet !== true)
|
|
2183
|
+
console.log(`${target}: removed ${key}`);
|
|
2134
2184
|
return 0;
|
|
2135
2185
|
}
|
|
2136
2186
|
async function transfer(key, from, to, newKey, replace) {
|
|
@@ -2156,8 +2206,9 @@ async function mv(args) {
|
|
|
2156
2206
|
const parsed = parse(args, mvUsage, {
|
|
2157
2207
|
from: { type: "string", description: "the file to take KEY from" },
|
|
2158
2208
|
to: { type: "string", description: "the file to put KEY in, created when missing" },
|
|
2159
|
-
force: { type: "boolean", description: "replace KEY when the target already sets it" }
|
|
2160
|
-
|
|
2209
|
+
force: { type: "boolean", description: "replace KEY when the target already sets it" },
|
|
2210
|
+
...QUIET
|
|
2211
|
+
}, { exits: MV_EXITS });
|
|
2161
2212
|
const [key] = parsed.positionals;
|
|
2162
2213
|
const { from, to, force } = parsed.values;
|
|
2163
2214
|
if (key === undefined || from === undefined || to === undefined)
|
|
@@ -2169,15 +2220,17 @@ ${mvUsage}`);
|
|
|
2169
2220
|
removeKey(source, key);
|
|
2170
2221
|
await writeEnv(from, source);
|
|
2171
2222
|
});
|
|
2172
|
-
|
|
2223
|
+
if (parsed.values.quiet !== true)
|
|
2224
|
+
console.log(`${key}: ${from} -> ${to}`);
|
|
2173
2225
|
return 0;
|
|
2174
2226
|
}
|
|
2175
2227
|
async function cp(args) {
|
|
2176
2228
|
const parsed = parse(args, cpUsage, {
|
|
2177
2229
|
from: { type: "string", description: "the file to take KEY from" },
|
|
2178
2230
|
to: { type: "string", description: "the file to put the copy in, created when missing" },
|
|
2179
|
-
as: { type: "string", description: "store the copy under this key instead" }
|
|
2180
|
-
|
|
2231
|
+
as: { type: "string", description: "store the copy under this key instead" },
|
|
2232
|
+
...QUIET
|
|
2233
|
+
}, { exits: CP_EXITS });
|
|
2181
2234
|
const [key] = parsed.positionals;
|
|
2182
2235
|
const { from, to, as } = parsed.values;
|
|
2183
2236
|
if (key === undefined || from === undefined || to === undefined)
|
|
@@ -2185,15 +2238,15 @@ async function cp(args) {
|
|
|
2185
2238
|
|
|
2186
2239
|
${cpUsage}`);
|
|
2187
2240
|
const { source, target, value, name } = await withLocks([from, to], async () => transfer(key, from, to, as, true));
|
|
2188
|
-
|
|
2189
|
-
|
|
2241
|
+
if (parsed.values.quiet !== true)
|
|
2242
|
+
console.log(`${to}: ${name}=${maskValue(name, value, await loadKnown(process.cwd(), [source, target])).replaceAll(`
|
|
2190
2243
|
`, "\\n")}`);
|
|
2191
2244
|
return 0;
|
|
2192
2245
|
}
|
|
2193
2246
|
|
|
2194
2247
|
// src/commands/pins.ts
|
|
2195
2248
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
2196
|
-
import { join as join10, resolve as
|
|
2249
|
+
import { join as join10, resolve as resolve5 } from "path";
|
|
2197
2250
|
|
|
2198
2251
|
// src/pins.ts
|
|
2199
2252
|
import { readdir as readdir3, readFile } from "fs/promises";
|
|
@@ -2376,8 +2429,8 @@ Checks that an app's tests pin the env that reaches outside.
|
|
|
2376
2429
|
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.
|
|
2377
2430
|
A file whose pages reach none of them says so with a \`// ev pins: none reached, <why>\` comment.
|
|
2378
2431
|
The dir is an app, or a monorepo holding apps one level down (the current folder by default).
|
|
2379
|
-
Reads variable names only, never a value
|
|
2380
|
-
|
|
2432
|
+
Reads variable names only, never a value.`;
|
|
2433
|
+
var EXITS2 = [[0, "everything is pinned"], [1, "something is not"], [2, "a usage error"]];
|
|
2381
2434
|
var options2 = {
|
|
2382
2435
|
json: jsonOption("each app with its reaching, unpinned variables and flagged test files"),
|
|
2383
2436
|
except: { type: "string", description: "comma-separated variables to leave out, as ones that only link back to the app" }
|
|
@@ -2410,9 +2463,9 @@ function name(app, root) {
|
|
|
2410
2463
|
return app.app === root ? app.app.split("/").at(-1) ?? app.app : app.app.slice(root.length + 1);
|
|
2411
2464
|
}
|
|
2412
2465
|
async function pins(args) {
|
|
2413
|
-
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"] });
|
|
2466
|
+
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"], exits: EXITS2 });
|
|
2414
2467
|
const json = parsed.values.json === true;
|
|
2415
|
-
const root =
|
|
2468
|
+
const root = resolve5(parsed.positionals[0] ?? ".");
|
|
2416
2469
|
const except = new Set((parsed.values.except ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== ""));
|
|
2417
2470
|
if (!await isFolder2(root))
|
|
2418
2471
|
fail(`${root} is not a folder`);
|
|
@@ -2444,16 +2497,14 @@ var listUsage = `ev list [file]
|
|
|
2444
2497
|
|
|
2445
2498
|
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.
|
|
2446
2499
|
|
|
2447
|
-
--json prints [{file, key, value, secret}], value masked and secret true when a value was
|
|
2448
|
-
|
|
2449
|
-
Exits 0 when it printed them, 1 when there is no .env* file, 2 on a usage error.`;
|
|
2500
|
+
--json prints [{file, key, value, secret}], value masked and secret true when a value was.`;
|
|
2501
|
+
var LIST_EXITS = [[0, "it printed them"], [1, "there is no .env* file"], [2, "a usage error"]];
|
|
2450
2502
|
var getUsage = `ev get KEY [file]
|
|
2451
2503
|
|
|
2452
2504
|
Prints the masked value of one key, from every .env* file that sets it or from one file.
|
|
2453
2505
|
|
|
2454
|
-
--json prints [{file, key, value, secret}] for each file that sets it
|
|
2455
|
-
|
|
2456
|
-
Exits 0 when the key is set, 1 when it is not set anywhere, 2 on a usage error.`;
|
|
2506
|
+
--json prints [{file, key, value, secret}] for each file that sets it.`;
|
|
2507
|
+
var GET_EXITS = [[0, "the key is set"], [1, "it is not set anywhere"], [2, "a usage error"]];
|
|
2457
2508
|
function display(key, value, known) {
|
|
2458
2509
|
return maskValue(key, value, known).replaceAll(`
|
|
2459
2510
|
`, "\\n").replaceAll("\r", "\\r");
|
|
@@ -2486,7 +2537,7 @@ async function readAll(names) {
|
|
|
2486
2537
|
return { files, known: await loadKnown(process.cwd(), files.map(([, file]) => file)) };
|
|
2487
2538
|
}
|
|
2488
2539
|
async function list(args) {
|
|
2489
|
-
const parsed = parse(args, listUsage, jsonFlag2);
|
|
2540
|
+
const parsed = parse(args, listUsage, jsonFlag2, { exits: LIST_EXITS });
|
|
2490
2541
|
const [file] = parsed.positionals;
|
|
2491
2542
|
const names = file === undefined ? await envFiles() : [file];
|
|
2492
2543
|
if (names.length === 0)
|
|
@@ -2504,7 +2555,7 @@ async function list(args) {
|
|
|
2504
2555
|
return 0;
|
|
2505
2556
|
}
|
|
2506
2557
|
async function get(args) {
|
|
2507
|
-
const parsed = parse(args, getUsage, jsonFlag2);
|
|
2558
|
+
const parsed = parse(args, getUsage, jsonFlag2, { exits: GET_EXITS });
|
|
2508
2559
|
const [key, file] = parsed.positionals;
|
|
2509
2560
|
if (key === undefined)
|
|
2510
2561
|
fail(`missing KEY
|
|
@@ -2527,19 +2578,17 @@ var grepUsage = `ev grep [-i] <regex> [file...]
|
|
|
2527
2578
|
|
|
2528
2579
|
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\`.
|
|
2529
2580
|
|
|
2530
|
-
--json prints [{file, key, value, secret}]
|
|
2531
|
-
|
|
2532
|
-
Exits 0 when a key matches, 1 when none does, 2 on a usage error.`;
|
|
2581
|
+
--json prints [{file, key, value, secret}].`;
|
|
2582
|
+
var GREP_EXITS = [[0, "a key matches"], [1, "none does"], [2, "a usage error"]];
|
|
2533
2583
|
var showUsage = `ev show <rev>:<file>
|
|
2534
2584
|
|
|
2535
2585
|
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\`.
|
|
2536
2586
|
|
|
2537
|
-
--json prints [{file, key, value, secret}]
|
|
2538
|
-
|
|
2539
|
-
Exits 0 when it printed them, 1 when git cannot show the file, 2 on a usage error.`;
|
|
2587
|
+
--json prints [{file, key, value, secret}].`;
|
|
2588
|
+
var SHOW_EXITS = [[0, "it printed them"], [1, "git cannot show the file"], [2, "a usage error"]];
|
|
2540
2589
|
var REVISION = /^([^:]+):(.+)$/;
|
|
2541
2590
|
async function grep(args) {
|
|
2542
|
-
const parsed = parse(args, grepUsage, { "ignore-case": { type: "boolean", short: "i", description: "match the key whatever its case" }, ...jsonFlag2 });
|
|
2591
|
+
const parsed = parse(args, grepUsage, { "ignore-case": { type: "boolean", short: "i", description: "match the key whatever its case" }, ...jsonFlag2 }, { exits: GREP_EXITS });
|
|
2543
2592
|
const [source, ...given] = parsed.positionals;
|
|
2544
2593
|
if (source === undefined)
|
|
2545
2594
|
fail(`missing the regex
|
|
@@ -2566,7 +2615,7 @@ ${grepUsage}`);
|
|
|
2566
2615
|
return 0;
|
|
2567
2616
|
}
|
|
2568
2617
|
async function show(args) {
|
|
2569
|
-
const parsed = parse(args, showUsage, jsonFlag2);
|
|
2618
|
+
const parsed = parse(args, showUsage, jsonFlag2, { exits: SHOW_EXITS });
|
|
2570
2619
|
const [target] = parsed.positionals;
|
|
2571
2620
|
const [, revision, path] = REVISION.exec(target ?? "") ?? [];
|
|
2572
2621
|
if (revision === undefined || path === undefined)
|
|
@@ -2589,7 +2638,7 @@ ${showUsage}`);
|
|
|
2589
2638
|
}
|
|
2590
2639
|
|
|
2591
2640
|
// src/commands/redact.ts
|
|
2592
|
-
import
|
|
2641
|
+
import process17 from "process";
|
|
2593
2642
|
|
|
2594
2643
|
// src/redactor.ts
|
|
2595
2644
|
var DIFF_START = /^(?:diff --git |@@ )/;
|
|
@@ -2710,15 +2759,14 @@ function check(text, known) {
|
|
|
2710
2759
|
var usage4 = `redact [--check]
|
|
2711
2760
|
|
|
2712
2761
|
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.
|
|
2713
|
-
--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
|
|
2714
|
-
|
|
2715
|
-
Exits 0 when it copied the input or found no secret, 1 when --check finds one, 2 on a usage error.`;
|
|
2762
|
+
--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\`.`;
|
|
2763
|
+
var EXITS3 = [[0, "it copied the input or found no secret"], [1, "--check finds one"], [2, "a usage error"]];
|
|
2716
2764
|
var options3 = {
|
|
2717
2765
|
check: { type: "boolean", description: "list where secrets are instead of masking them, exit 1 when found" },
|
|
2718
2766
|
"no-env": { type: "boolean", description: "do not search for the values of the .env* files" }
|
|
2719
2767
|
};
|
|
2720
2768
|
async function redact(args) {
|
|
2721
|
-
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"]] });
|
|
2769
|
+
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"]] });
|
|
2722
2770
|
const known = parsed.values["no-env"] === true ? undefined : await loadKnown();
|
|
2723
2771
|
if (parsed.values.check === true) {
|
|
2724
2772
|
const findings = check(await readInput("-"), known);
|
|
@@ -2729,13 +2777,13 @@ async function redact(args) {
|
|
|
2729
2777
|
const redactor = new Redactor(known);
|
|
2730
2778
|
const decoder = new TextDecoder;
|
|
2731
2779
|
for await (const chunk of Bun.stdin.stream())
|
|
2732
|
-
|
|
2733
|
-
|
|
2780
|
+
process17.stdout.write(redactor.push(decoder.decode(chunk, { stream: true })));
|
|
2781
|
+
process17.stdout.write(redactor.push(decoder.decode()) + redactor.end());
|
|
2734
2782
|
return 0;
|
|
2735
2783
|
}
|
|
2736
2784
|
|
|
2737
2785
|
// src/ev.ts
|
|
2738
|
-
|
|
2786
|
+
process18.exitCode = await runCli({
|
|
2739
2787
|
name: "ev",
|
|
2740
2788
|
about: ".env files listed and edited with secrets masked",
|
|
2741
2789
|
replaces: "cat .env, grep on env files and editing them by hand",
|