@kaynooo/cli-env 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ev.js +350 -103
- package/dist/redact.js +304 -73
- package/package.json +2 -2
- package/src/commands/audit.ts +5 -3
- package/src/commands/compare.ts +9 -3
- package/src/commands/read.ts +18 -4
package/src/commands/compare.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { fail, jsonOption, parse, printJson, role } from '@kaynooo/cli-kit'
|
|
2
3
|
import { entries } from '../dotenv'
|
|
3
4
|
import { readEnv } from '../files'
|
|
4
5
|
|
|
@@ -43,7 +44,9 @@ export async function diff(args: string[]): Promise<number> {
|
|
|
43
44
|
return onlyA.length + onlyB.length === 0 ? 0 : 1
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const
|
|
47
|
+
const path = role('path', process.stdout)
|
|
48
|
+
const value = role('value', process.stdout)
|
|
49
|
+
const lines = [...onlyA.map(key => `only in ${path(a)}: ${value(key)}`), ...onlyB.map(key => `only in ${path(b)}: ${value(key)}`)]
|
|
47
50
|
|
|
48
51
|
if (lines.length === 0)
|
|
49
52
|
return 0
|
|
@@ -71,7 +74,10 @@ export async function missing(args: string[]): Promise<number> {
|
|
|
71
74
|
if (absent.length === 0)
|
|
72
75
|
return 0
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
const path = role('path', process.stdout)
|
|
78
|
+
const value = role('value', process.stdout)
|
|
79
|
+
|
|
80
|
+
console.log(absent.map(key => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join('\n'))
|
|
75
81
|
|
|
76
82
|
return 1
|
|
77
83
|
}
|
package/src/commands/read.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dotenv } from '../dotenv'
|
|
2
2
|
import type { KnownSecrets } from '../mask'
|
|
3
|
-
import { fail, jsonOption, parse, printJson, table } from '@kaynooo/cli-kit'
|
|
3
|
+
import { fail, jsonOption, parse, printJson, role, table } from '@kaynooo/cli-kit'
|
|
4
4
|
import { $ } from 'bun'
|
|
5
5
|
import { entries, parseDotenv } from '../dotenv'
|
|
6
6
|
import { envFiles, loadKnown, readEnv } from '../files'
|
|
@@ -30,6 +30,20 @@ const jsonFlag = { json: jsonOption() } as const
|
|
|
30
30
|
|
|
31
31
|
interface Row { file: string, key: string, value: string, secret: boolean }
|
|
32
32
|
|
|
33
|
+
// A row per key with its file name in the path colour and the key bold on a terminal.
|
|
34
|
+
function keyTable(rows: Row[]): string {
|
|
35
|
+
const path = role('path', process.stdout)
|
|
36
|
+
const key = role('value', process.stdout)
|
|
37
|
+
|
|
38
|
+
return table(rows.map(each => [path(each.file), key(each.key), each.value]))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function fileTable(rows: Row[]): string {
|
|
42
|
+
const path = role('path', process.stdout)
|
|
43
|
+
|
|
44
|
+
return table(rows.map(each => [path(each.file), each.value]))
|
|
45
|
+
}
|
|
46
|
+
|
|
33
47
|
// A value is secret when it is masked, or when its key is named like a secret even with nothing to mask.
|
|
34
48
|
function row(file: string, key: string, value: string, known: KnownSecrets): Row {
|
|
35
49
|
const shown = display(key, value, known)
|
|
@@ -74,7 +88,7 @@ export async function list(args: string[]): Promise<number> {
|
|
|
74
88
|
|
|
75
89
|
printRows(rows, parsed.values.json === true, () => {
|
|
76
90
|
if (rows.length > 0)
|
|
77
|
-
console.log(
|
|
91
|
+
console.log(keyTable(rows))
|
|
78
92
|
})
|
|
79
93
|
|
|
80
94
|
return 0
|
|
@@ -103,7 +117,7 @@ export async function get(args: string[]): Promise<number> {
|
|
|
103
117
|
if (rows.length === 0)
|
|
104
118
|
fail(`${key} is not set in ${file ?? 'any .env* file'}`, 1)
|
|
105
119
|
|
|
106
|
-
printRows(rows, parsed.values.json === true, () => console.log(file === undefined ?
|
|
120
|
+
printRows(rows, parsed.values.json === true, () => console.log(file === undefined ? fileTable(rows) : rows[0]?.value))
|
|
107
121
|
|
|
108
122
|
return 0
|
|
109
123
|
}
|
|
@@ -158,7 +172,7 @@ export async function grep(args: string[]): Promise<number> {
|
|
|
158
172
|
if (rows.length === 0)
|
|
159
173
|
fail(`no key matches ${source} in ${names.join(', ') || 'any .env* file'}`, 1)
|
|
160
174
|
|
|
161
|
-
printRows(rows, parsed.values.json === true, () => console.log(
|
|
175
|
+
printRows(rows, parsed.values.json === true, () => console.log(keyTable(rows)))
|
|
162
176
|
|
|
163
177
|
return 0
|
|
164
178
|
}
|