@karmaniverous/get-dotenv 6.0.0-0 → 6.0.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/README.md +86 -334
- package/dist/cli.d.ts +569 -0
- package/dist/cli.mjs +18788 -0
- package/dist/cliHost.d.ts +548 -253
- package/dist/cliHost.mjs +1990 -1458
- package/dist/config.d.ts +192 -14
- package/dist/config.mjs +256 -81
- package/dist/env-overlay.d.ts +226 -18
- package/dist/env-overlay.mjs +181 -22
- package/dist/getdotenv.cli.mjs +18166 -3437
- package/dist/index.d.ts +729 -136
- package/dist/index.mjs +18207 -3457
- package/dist/plugins-aws.d.ts +289 -104
- package/dist/plugins-aws.mjs +2462 -350
- package/dist/plugins-batch.d.ts +355 -105
- package/dist/plugins-batch.mjs +2595 -420
- package/dist/plugins-cmd.d.ts +287 -118
- package/dist/plugins-cmd.mjs +2661 -839
- package/dist/plugins-init.d.ts +272 -100
- package/dist/plugins-init.mjs +2152 -37
- package/dist/plugins.d.ts +323 -140
- package/dist/plugins.mjs +18006 -2025
- package/dist/templates/cli/index.ts +26 -0
- package/dist/templates/cli/plugins/hello.ts +43 -0
- package/dist/templates/config/js/getdotenv.config.js +20 -0
- package/dist/templates/config/json/local/getdotenv.config.local.json +7 -0
- package/dist/templates/config/json/public/getdotenv.config.json +9 -0
- package/dist/templates/config/public/getdotenv.config.json +8 -0
- package/dist/templates/config/ts/getdotenv.config.ts +28 -0
- package/dist/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/config/yaml/public/getdotenv.config.yaml +7 -0
- package/dist/templates/getdotenv.config.js +20 -0
- package/dist/templates/getdotenv.config.json +9 -0
- package/dist/templates/getdotenv.config.local.json +7 -0
- package/dist/templates/getdotenv.config.local.yaml +7 -0
- package/dist/templates/getdotenv.config.ts +28 -0
- package/dist/templates/getdotenv.config.yaml +7 -0
- package/dist/templates/hello.ts +43 -0
- package/dist/templates/index.ts +26 -0
- package/dist/templates/js/getdotenv.config.js +20 -0
- package/dist/templates/json/local/getdotenv.config.local.json +7 -0
- package/dist/templates/json/public/getdotenv.config.json +9 -0
- package/dist/templates/local/getdotenv.config.local.json +7 -0
- package/dist/templates/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/plugins/hello.ts +43 -0
- package/dist/templates/public/getdotenv.config.json +9 -0
- package/dist/templates/public/getdotenv.config.yaml +7 -0
- package/dist/templates/ts/getdotenv.config.ts +28 -0
- package/dist/templates/yaml/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/yaml/public/getdotenv.config.yaml +7 -0
- package/getdotenv.config.json +1 -19
- package/package.json +52 -89
- package/templates/cli/index.ts +26 -0
- package/templates/cli/plugins/hello.ts +43 -0
- package/templates/config/js/getdotenv.config.js +9 -4
- package/templates/config/json/public/getdotenv.config.json +0 -3
- package/templates/config/public/getdotenv.config.json +0 -5
- package/templates/config/ts/getdotenv.config.ts +17 -5
- package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
- package/dist/cliHost.cjs +0 -2078
- package/dist/cliHost.d.cts +0 -451
- package/dist/cliHost.d.mts +0 -451
- package/dist/config.cjs +0 -252
- package/dist/config.d.cts +0 -55
- package/dist/config.d.mts +0 -55
- package/dist/env-overlay.cjs +0 -163
- package/dist/env-overlay.d.cts +0 -50
- package/dist/env-overlay.d.mts +0 -50
- package/dist/index.cjs +0 -4077
- package/dist/index.d.cts +0 -318
- package/dist/index.d.mts +0 -318
- package/dist/plugins-aws.cjs +0 -666
- package/dist/plugins-aws.d.cts +0 -158
- package/dist/plugins-aws.d.mts +0 -158
- package/dist/plugins-batch.cjs +0 -658
- package/dist/plugins-batch.d.cts +0 -181
- package/dist/plugins-batch.d.mts +0 -181
- package/dist/plugins-cmd.cjs +0 -1112
- package/dist/plugins-cmd.d.cts +0 -178
- package/dist/plugins-cmd.d.mts +0 -178
- package/dist/plugins-demo.cjs +0 -352
- package/dist/plugins-demo.d.cts +0 -158
- package/dist/plugins-demo.d.mts +0 -158
- package/dist/plugins-demo.d.ts +0 -158
- package/dist/plugins-demo.mjs +0 -350
- package/dist/plugins-init.cjs +0 -289
- package/dist/plugins-init.d.cts +0 -162
- package/dist/plugins-init.d.mts +0 -162
- package/dist/plugins.cjs +0 -2327
- package/dist/plugins.d.cts +0 -211
- package/dist/plugins.d.mts +0 -211
- package/templates/cli/ts/index.ts +0 -9
- package/templates/cli/ts/plugins/hello.ts +0 -17
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { z, ZodObject } from 'zod';
|
|
2
|
+
import { OptionValues, Command, InferCommandArguments, Option, CommandUnknownOpts } from '@commander-js/extra-typings';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal root options shape shared by CLI and generator layers.
|
|
6
|
+
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
interface RootOptionsShape {
|
|
11
|
+
/** Target environment (dotenv-expanded). */
|
|
12
|
+
env?: string;
|
|
13
|
+
/** Explicit variable overrides (dotenv-expanded). */
|
|
14
|
+
vars?: string;
|
|
15
|
+
/** Command to execute (dotenv-expanded). */
|
|
16
|
+
command?: string;
|
|
17
|
+
/** Output path for the consolidated environment file (dotenv-expanded). */
|
|
18
|
+
outputPath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Shell execution strategy.
|
|
21
|
+
* - `true`: use default OS shell.
|
|
22
|
+
* - `false`: use plain execution (no shell).
|
|
23
|
+
* - string: use specific shell path.
|
|
24
|
+
*/
|
|
25
|
+
shell?: string | boolean;
|
|
26
|
+
/** Whether to load variables into `process.env`. */
|
|
27
|
+
loadProcess?: boolean;
|
|
28
|
+
/** Exclude all variables from loading. */
|
|
29
|
+
excludeAll?: boolean;
|
|
30
|
+
/** Exclude dynamic variables. */
|
|
31
|
+
excludeDynamic?: boolean;
|
|
32
|
+
/** Exclude environment-specific variables. */
|
|
33
|
+
excludeEnv?: boolean;
|
|
34
|
+
/** Exclude global variables. */
|
|
35
|
+
excludeGlobal?: boolean;
|
|
36
|
+
/** Exclude private variables. */
|
|
37
|
+
excludePrivate?: boolean;
|
|
38
|
+
/** Exclude public variables. */
|
|
39
|
+
excludePublic?: boolean;
|
|
40
|
+
/** Enable console logging of loaded variables. */
|
|
41
|
+
log?: boolean;
|
|
42
|
+
/** Enable debug logging to stderr. */
|
|
43
|
+
debug?: boolean;
|
|
44
|
+
/** Capture child process stdio (useful for tests/CI). */
|
|
45
|
+
capture?: boolean;
|
|
46
|
+
/** Fail on validation errors (schema/requiredKeys). */
|
|
47
|
+
strict?: boolean;
|
|
48
|
+
/** Enable presentation-time redaction of secret-like keys. */
|
|
49
|
+
redact?: boolean;
|
|
50
|
+
/** Enable entropy warnings for high-entropy values. */
|
|
51
|
+
warnEntropy?: boolean;
|
|
52
|
+
/** Entropy threshold (bits/char) for warnings (default 3.8). */
|
|
53
|
+
entropyThreshold?: number;
|
|
54
|
+
/** Minimum string length to check for entropy (default 16). */
|
|
55
|
+
entropyMinLength?: number;
|
|
56
|
+
/** Regex patterns for keys to exclude from entropy checks. */
|
|
57
|
+
entropyWhitelist?: ReadonlyArray<string>;
|
|
58
|
+
/** Additional regex patterns for keys to redact. */
|
|
59
|
+
redactPatterns?: string[];
|
|
60
|
+
/** Default target environment when not specified. */
|
|
61
|
+
defaultEnv?: string;
|
|
62
|
+
/** Token indicating a dotenv file (default: ".env"). */
|
|
63
|
+
dotenvToken?: string;
|
|
64
|
+
/** Path to dynamic variables module (default: undefined). */
|
|
65
|
+
dynamicPath?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Emit diagnostics for child env composition.
|
|
68
|
+
* - `true`: trace all keys.
|
|
69
|
+
* - `string[]`: trace selected keys.
|
|
70
|
+
*/
|
|
71
|
+
trace?: boolean | string[];
|
|
72
|
+
/** Paths to search for dotenv files (space-delimited string or array). */
|
|
73
|
+
paths?: string;
|
|
74
|
+
/** Delimiter for paths string (default: space). */
|
|
75
|
+
pathsDelimiter?: string;
|
|
76
|
+
/** Regex pattern for paths delimiter. */
|
|
77
|
+
pathsDelimiterPattern?: string;
|
|
78
|
+
/** Token indicating private variables (default: "local"). */
|
|
79
|
+
privateToken?: string;
|
|
80
|
+
/** Delimiter for vars string (default: space). */
|
|
81
|
+
varsDelimiter?: string;
|
|
82
|
+
/** Regex pattern for vars delimiter. */
|
|
83
|
+
varsDelimiterPattern?: string;
|
|
84
|
+
/** Assignment operator for vars (default: "="). */
|
|
85
|
+
varsAssignor?: string;
|
|
86
|
+
/** Regex pattern for vars assignment operator. */
|
|
87
|
+
varsAssignorPattern?: string;
|
|
88
|
+
/** Table of named scripts for execution. */
|
|
89
|
+
scripts?: ScriptsTable;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Definition for a single script entry.
|
|
93
|
+
*/
|
|
94
|
+
interface ScriptDef<TShell extends string | boolean = string | boolean> {
|
|
95
|
+
/** The command string to execute. */
|
|
96
|
+
cmd: string;
|
|
97
|
+
/** Shell override for this script. */
|
|
98
|
+
shell?: TShell | undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Scripts table shape.
|
|
102
|
+
*/
|
|
103
|
+
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | ScriptDef<TShell>>;
|
|
104
|
+
/**
|
|
105
|
+
* Per-invocation context shared with plugins and actions.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> {
|
|
110
|
+
optionsResolved: TOptions;
|
|
111
|
+
dotenv: ProcessEnv;
|
|
112
|
+
plugins?: Record<string, unknown>;
|
|
113
|
+
pluginConfigs?: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Options for branding the CLI.
|
|
117
|
+
*
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
interface BrandOptions {
|
|
121
|
+
/** CLI name. */
|
|
122
|
+
name?: string;
|
|
123
|
+
/** CLI description. */
|
|
124
|
+
description?: string;
|
|
125
|
+
/** CLI version string. */
|
|
126
|
+
version?: string;
|
|
127
|
+
/** Import URL for resolving package version. */
|
|
128
|
+
importMetaUrl?: string;
|
|
129
|
+
/** Custom help header text. */
|
|
130
|
+
helpHeader?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Resolved CLI options schema.
|
|
135
|
+
* For the current step this mirrors the RAW schema; later stages may further
|
|
136
|
+
* narrow types post-resolution in the host pipeline.
|
|
137
|
+
*/
|
|
138
|
+
declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
139
|
+
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
140
|
+
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
141
|
+
dynamicPath: z.ZodOptional<z.ZodString>;
|
|
142
|
+
dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
143
|
+
env: z.ZodOptional<z.ZodString>;
|
|
144
|
+
excludeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
145
|
+
excludeEnv: z.ZodOptional<z.ZodBoolean>;
|
|
146
|
+
excludeGlobal: z.ZodOptional<z.ZodBoolean>;
|
|
147
|
+
excludePrivate: z.ZodOptional<z.ZodBoolean>;
|
|
148
|
+
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
149
|
+
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
150
|
+
log: z.ZodOptional<z.ZodBoolean>;
|
|
151
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
152
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
153
|
+
privateToken: z.ZodOptional<z.ZodString>;
|
|
154
|
+
debug: z.ZodOptional<z.ZodBoolean>;
|
|
155
|
+
strict: z.ZodOptional<z.ZodBoolean>;
|
|
156
|
+
capture: z.ZodOptional<z.ZodBoolean>;
|
|
157
|
+
trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
158
|
+
redact: z.ZodOptional<z.ZodBoolean>;
|
|
159
|
+
warnEntropy: z.ZodOptional<z.ZodBoolean>;
|
|
160
|
+
entropyThreshold: z.ZodOptional<z.ZodNumber>;
|
|
161
|
+
entropyMinLength: z.ZodOptional<z.ZodNumber>;
|
|
162
|
+
entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
163
|
+
redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
164
|
+
paths: z.ZodOptional<z.ZodString>;
|
|
165
|
+
pathsDelimiter: z.ZodOptional<z.ZodString>;
|
|
166
|
+
pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
167
|
+
scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
168
|
+
shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
169
|
+
vars: z.ZodOptional<z.ZodString>;
|
|
170
|
+
varsAssignor: z.ZodOptional<z.ZodString>;
|
|
171
|
+
varsAssignorPattern: z.ZodOptional<z.ZodString>;
|
|
172
|
+
varsDelimiter: z.ZodOptional<z.ZodString>;
|
|
173
|
+
varsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Resolved programmatic options schema (post-inheritance).
|
|
178
|
+
* For now, this mirrors the RAW schema; future stages may materialize defaults
|
|
179
|
+
* and narrow shapes as resolution is wired into the host.
|
|
180
|
+
*/
|
|
181
|
+
declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
182
|
+
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
183
|
+
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
184
|
+
dynamicPath: z.ZodOptional<z.ZodString>;
|
|
185
|
+
dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
186
|
+
env: z.ZodOptional<z.ZodString>;
|
|
187
|
+
excludeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
188
|
+
excludeEnv: z.ZodOptional<z.ZodBoolean>;
|
|
189
|
+
excludeGlobal: z.ZodOptional<z.ZodBoolean>;
|
|
190
|
+
excludePrivate: z.ZodOptional<z.ZodBoolean>;
|
|
191
|
+
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
192
|
+
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
193
|
+
log: z.ZodOptional<z.ZodBoolean>;
|
|
194
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
195
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
196
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
197
|
+
privateToken: z.ZodOptional<z.ZodString>;
|
|
198
|
+
vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
|
199
|
+
}, z.core.$strip>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Canonical programmatic options and helpers for get-dotenv.
|
|
203
|
+
*
|
|
204
|
+
* Requirements addressed:
|
|
205
|
+
* - GetDotenvOptions derives from the Zod schema output (single source of truth).
|
|
206
|
+
* - Removed deprecated/compat flags from the public shape (e.g., useConfigLoader).
|
|
207
|
+
* - Provide Vars-aware defineDynamic and a typed config builder defineGetDotenvConfig\<Vars, Env\>().
|
|
208
|
+
* - Preserve existing behavior for defaults resolution and compat converters.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A minimal representation of an environment key/value mapping.
|
|
213
|
+
* Values may be `undefined` to represent "unset".
|
|
214
|
+
*/
|
|
215
|
+
type ProcessEnv = Record<string, string | undefined>;
|
|
216
|
+
/**
|
|
217
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
218
|
+
* and the selected environment (if any), and returns either a string to set
|
|
219
|
+
* or `undefined` to unset/skip the variable.
|
|
220
|
+
*/
|
|
221
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* A map of dynamic variable definitions.
|
|
224
|
+
* Keys are variable names; values are either literal strings or functions.
|
|
225
|
+
*/
|
|
226
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
227
|
+
/**
|
|
228
|
+
* Logger interface compatible with `console` or a subset thereof.
|
|
229
|
+
*/
|
|
230
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
231
|
+
/**
|
|
232
|
+
* Canonical programmatic options type (schema-derived).
|
|
233
|
+
* This type is the single source of truth for programmatic options.
|
|
234
|
+
*/
|
|
235
|
+
type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
|
|
236
|
+
/**
|
|
237
|
+
* Compile-time overlay: narrowed logger for DX (schema stores unknown).
|
|
238
|
+
*/
|
|
239
|
+
logger: Logger;
|
|
240
|
+
/**
|
|
241
|
+
* Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
|
|
242
|
+
*/
|
|
243
|
+
dynamic?: GetDotenvDynamic;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Unify Scripts via the generic ScriptsTable<TShell> so shell types propagate.
|
|
248
|
+
*/
|
|
249
|
+
type Scripts = ScriptsTable;
|
|
250
|
+
/**
|
|
251
|
+
* Canonical CLI options type derived from the Zod schema output.
|
|
252
|
+
* Includes CLI-only flags (debug/strict/capture/trace/redaction/entropy),
|
|
253
|
+
* stringly paths/vars, and inherited programmatic fields (minus normalized
|
|
254
|
+
* shapes that are handled by resolution).
|
|
255
|
+
*/
|
|
256
|
+
type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
|
|
257
|
+
/**
|
|
258
|
+
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
259
|
+
*/
|
|
260
|
+
logger: Logger;
|
|
261
|
+
/**
|
|
262
|
+
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
263
|
+
*/
|
|
264
|
+
scripts?: Scripts;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Configuration context used for generating dynamic help descriptions.
|
|
269
|
+
* Contains merged CLI options and plugin configuration slices.
|
|
270
|
+
*
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
|
|
274
|
+
/**
|
|
275
|
+
* Per‑plugin configuration slices keyed by realized mount path
|
|
276
|
+
* (e.g., `"aws"` or `"aws/whoami"`), used for dynamic help text.
|
|
277
|
+
*/
|
|
278
|
+
plugins: Record<string, unknown>;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/** src/cliHost/definePlugin/contracts.ts
|
|
282
|
+
* Public contracts for plugin authoring (types only).
|
|
283
|
+
* - No runtime logic or state.
|
|
284
|
+
* - Safe to import broadly without introducing cycles.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Options for resolving and loading the configuration.
|
|
289
|
+
*
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
interface ResolveAndLoadOptions {
|
|
293
|
+
/**
|
|
294
|
+
* When false, skips running plugin afterResolve hooks.
|
|
295
|
+
* Useful for top-level help rendering to avoid long-running side-effects
|
|
296
|
+
* while still evaluating dynamic help text.
|
|
297
|
+
*
|
|
298
|
+
* @default true
|
|
299
|
+
*/
|
|
300
|
+
runAfterResolve?: boolean;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Structural public interface for the host exposed to plugins.
|
|
304
|
+
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
305
|
+
* - Adds host-specific helpers used by built-in plugins.
|
|
306
|
+
*
|
|
307
|
+
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
308
|
+
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
309
|
+
*/
|
|
310
|
+
interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends Command<TArgs, TOpts, TGlobal> {
|
|
311
|
+
/**
|
|
312
|
+
* Create a namespaced child command with argument inference.
|
|
313
|
+
* Mirrors Commander generics so downstream chaining remains fully typed.
|
|
314
|
+
*/
|
|
315
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
316
|
+
...TArgs,
|
|
317
|
+
...InferCommandArguments<Usage>
|
|
318
|
+
], {}, TOpts & TGlobal>;
|
|
319
|
+
/** Return the current context; throws if not yet resolved. */
|
|
320
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
321
|
+
/** Check whether a context has been resolved (non-throwing). */
|
|
322
|
+
hasCtx(): boolean;
|
|
323
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
324
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
325
|
+
/**
|
|
326
|
+
* Create a dynamic option whose description is computed at help time
|
|
327
|
+
* from the resolved configuration.
|
|
328
|
+
*/
|
|
329
|
+
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
330
|
+
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Optional overrides for plugin composition.
|
|
334
|
+
*
|
|
335
|
+
* @public
|
|
336
|
+
*/
|
|
337
|
+
interface PluginNamespaceOverride {
|
|
338
|
+
/**
|
|
339
|
+
* Override the default namespace for this plugin instance.
|
|
340
|
+
*/
|
|
341
|
+
ns?: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* An entry in the plugin children array.
|
|
345
|
+
*
|
|
346
|
+
* @public
|
|
347
|
+
*/
|
|
348
|
+
interface PluginChildEntry<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
349
|
+
/** The child plugin instance to mount under this parent. */
|
|
350
|
+
plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
351
|
+
/**
|
|
352
|
+
* Optional namespace override for the child when mounted under the parent.
|
|
353
|
+
* When provided, this name is used instead of the child's default `ns`.
|
|
354
|
+
*/
|
|
355
|
+
override: PluginNamespaceOverride | undefined;
|
|
356
|
+
}
|
|
357
|
+
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
358
|
+
interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
359
|
+
/** Namespace (required): the command name where this plugin is mounted. */
|
|
360
|
+
ns: string;
|
|
361
|
+
/**
|
|
362
|
+
* Setup phase: register commands and wiring on the provided mount.
|
|
363
|
+
* Runs parent → children (pre-order). Return nothing (void).
|
|
364
|
+
*/
|
|
365
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
368
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
369
|
+
* Runs parent → children (pre-order).
|
|
370
|
+
*/
|
|
371
|
+
afterResolve?: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
|
|
372
|
+
/** Zod schema for this plugin's config slice (from config.plugins[…]). */
|
|
373
|
+
configSchema?: ZodObject;
|
|
374
|
+
/**
|
|
375
|
+
* Compositional children, with optional per-child overrides (e.g., ns).
|
|
376
|
+
* Installed after the parent per pre-order.
|
|
377
|
+
*/
|
|
378
|
+
children: Array<PluginChildEntry<TOptions, TArgs, TOpts, TGlobal>>;
|
|
379
|
+
/**
|
|
380
|
+
* Compose a child plugin with optional override (ns). Returns the parent
|
|
381
|
+
* to enable chaining.
|
|
382
|
+
*/
|
|
383
|
+
use: (child: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride) => GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** src/cliHost/GetDotenvCli.ts
|
|
387
|
+
* Plugin-first CLI host for get-dotenv with Commander generics preserved.
|
|
388
|
+
* Public surface implements GetDotenvCliPublic and provides:
|
|
389
|
+
* - attachRootOptions (builder-only; no public override wiring)
|
|
390
|
+
* - resolveAndLoad (strict resolve + context compute)
|
|
391
|
+
* - getCtx/hasCtx accessors
|
|
392
|
+
* - ns() for typed subcommand creation with duplicate-name guard
|
|
393
|
+
* - grouped help rendering with dynamic option descriptions
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
declare const CTX_SYMBOL: unique symbol;
|
|
397
|
+
declare const OPTS_SYMBOL: unique symbol;
|
|
398
|
+
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
399
|
+
/**
|
|
400
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
401
|
+
*
|
|
402
|
+
* Responsibilities:
|
|
403
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
404
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
405
|
+
* - Provide a namespacing helper (ns).
|
|
406
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
407
|
+
*/
|
|
408
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends Command<TArgs, TOpts, TGlobal> implements GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal> {
|
|
409
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
410
|
+
private _plugins;
|
|
411
|
+
/** One-time installation guard */
|
|
412
|
+
private _installed;
|
|
413
|
+
/** In-flight installation promise to guard against concurrent installs */
|
|
414
|
+
private _installing?;
|
|
415
|
+
/** Optional header line to prepend in help output */
|
|
416
|
+
private [HELP_HEADER_SYMBOL];
|
|
417
|
+
/** Context/options stored under symbols (typed) */
|
|
418
|
+
private [CTX_SYMBOL]?;
|
|
419
|
+
private [OPTS_SYMBOL]?;
|
|
420
|
+
/**
|
|
421
|
+
* Create a subcommand using the same subclass, preserving helpers like
|
|
422
|
+
* dynamicOption on children.
|
|
423
|
+
*/
|
|
424
|
+
createCommand(name?: string): GetDotenvCli<TOptions>;
|
|
425
|
+
constructor(alias?: string);
|
|
426
|
+
/**
|
|
427
|
+
* Attach legacy/base root flags to this CLI instance.
|
|
428
|
+
* Delegates to the pure builder in attachRootOptions.ts.
|
|
429
|
+
*/
|
|
430
|
+
attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
431
|
+
/**
|
|
432
|
+
* Resolve options (strict) and compute dotenv context.
|
|
433
|
+
* Stores the context on the instance under a symbol.
|
|
434
|
+
*
|
|
435
|
+
* Options:
|
|
436
|
+
* - opts.runAfterResolve (default true): when false, skips running plugin
|
|
437
|
+
* afterResolve hooks. Useful for top-level help rendering to avoid
|
|
438
|
+
* long-running side-effects while still evaluating dynamic help text.
|
|
439
|
+
*/
|
|
440
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
441
|
+
/**
|
|
442
|
+
* Create a Commander Option that computes its description at help time.
|
|
443
|
+
* The returned Option may be configured (conflicts, default, parser) and
|
|
444
|
+
* added via addOption().
|
|
445
|
+
*/
|
|
446
|
+
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
447
|
+
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
448
|
+
/**
|
|
449
|
+
* Evaluate dynamic descriptions for this command and all descendants using
|
|
450
|
+
* the provided resolved configuration. Mutates the Option.description in
|
|
451
|
+
* place so Commander help renders updated text.
|
|
452
|
+
*/
|
|
453
|
+
evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
|
|
454
|
+
/** Internal: climb to the true root (host) command. */
|
|
455
|
+
private _root;
|
|
456
|
+
/**
|
|
457
|
+
* Retrieve the current invocation context (if any).
|
|
458
|
+
*/
|
|
459
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
460
|
+
/**
|
|
461
|
+
* Check whether a context has been resolved (non-throwing guard).
|
|
462
|
+
*/
|
|
463
|
+
hasCtx(): boolean;
|
|
464
|
+
/**
|
|
465
|
+
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
466
|
+
* Downstream-safe: no generics required.
|
|
467
|
+
*/
|
|
468
|
+
getOptions(): GetDotenvCliOptions | undefined;
|
|
469
|
+
/** Internal: set the merged root options bag for this run. */
|
|
470
|
+
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
471
|
+
/**
|
|
472
|
+
* Convenience helper to create a namespaced subcommand with argument inference.
|
|
473
|
+
* This mirrors Commander generics so downstream chaining stays fully typed.
|
|
474
|
+
*/
|
|
475
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
476
|
+
...TArgs,
|
|
477
|
+
...InferCommandArguments<Usage>
|
|
478
|
+
], {}, TOpts & TGlobal>;
|
|
479
|
+
/**
|
|
480
|
+
* Tag options added during the provided callback as 'app' for grouped help.
|
|
481
|
+
* Allows downstream apps to demarcate their root-level options.
|
|
482
|
+
*/
|
|
483
|
+
tagAppOptions<T>(fn: (root: CommandUnknownOpts) => T): T;
|
|
484
|
+
/**
|
|
485
|
+
* Branding helper: set CLI name/description/version and optional help header.
|
|
486
|
+
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
487
|
+
* nearest package.json version (best-effort; non-fatal on failure).
|
|
488
|
+
*/
|
|
489
|
+
brand(args: BrandOptions): Promise<this>;
|
|
490
|
+
/**
|
|
491
|
+
* Insert grouped plugin/app options between "Options" and "Commands" for
|
|
492
|
+
* hybrid ordering. Applies to root and any parent command.
|
|
493
|
+
*/
|
|
494
|
+
helpInformation(): string;
|
|
495
|
+
/**
|
|
496
|
+
* Public: tag an Option with a display group for help (root/app/plugin:<id>).
|
|
497
|
+
*/
|
|
498
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
499
|
+
/**
|
|
500
|
+
* Register a plugin for installation (parent level).
|
|
501
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
502
|
+
*/
|
|
503
|
+
use(plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride): this;
|
|
504
|
+
/**
|
|
505
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
506
|
+
* Runs only once per CLI instance.
|
|
507
|
+
*/
|
|
508
|
+
install(): Promise<void>;
|
|
509
|
+
/**
|
|
510
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
511
|
+
*/
|
|
512
|
+
private _runAfterResolve;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Create a get-dotenv CLI host with included plugins.
|
|
517
|
+
*
|
|
518
|
+
* Options:
|
|
519
|
+
* - alias: command name used for help/argv scaffolding (default: "getdotenv")
|
|
520
|
+
* - branding: optional help header; when omitted, brand() uses "<alias> v<version>"
|
|
521
|
+
*
|
|
522
|
+
* Usage:
|
|
523
|
+
* ```ts
|
|
524
|
+
* import { createCli } from '@karmaniverous/get-dotenv';
|
|
525
|
+
*
|
|
526
|
+
* await createCli({
|
|
527
|
+
* alias: 'getdotenv',
|
|
528
|
+
* branding: 'getdotenv vX.Y.Z'
|
|
529
|
+
* })();
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
type CreateCliOptions = {
|
|
533
|
+
/**
|
|
534
|
+
* CLI command name used for help and argv scaffolding.
|
|
535
|
+
* Defaults to `'getdotenv'` when omitted.
|
|
536
|
+
*/
|
|
537
|
+
alias?: string;
|
|
538
|
+
/**
|
|
539
|
+
* Optional help header text. When omitted, brand() uses
|
|
540
|
+
* `"<alias> v<resolved-version>"` if a version can be read.
|
|
541
|
+
*/
|
|
542
|
+
branding?: string;
|
|
543
|
+
/**
|
|
544
|
+
* Optional composer to wire the CLI (plugins/options). If not provided,
|
|
545
|
+
* the shipped default wiring is applied. Any `configureOutput`/`exitOverride`
|
|
546
|
+
* you call here override the defaults.
|
|
547
|
+
*/
|
|
548
|
+
compose?: (program: GetDotenvCli) => GetDotenvCli;
|
|
549
|
+
/**
|
|
550
|
+
* Root defaults applied once before composition. These are used by flag declaration
|
|
551
|
+
* and merge-time defaults (and top-level -h parity labels).
|
|
552
|
+
* Note: shipped CLI does not force loadProcess OFF; base defaults apply unless set here.
|
|
553
|
+
*/
|
|
554
|
+
rootOptionDefaults?: Partial<RootOptionsShape>;
|
|
555
|
+
/**
|
|
556
|
+
* Visibility map to hide families/singles from root help. When a key is false,
|
|
557
|
+
* the corresponding option(s) are hidden (via hideHelp) after flags are declared.
|
|
558
|
+
*/
|
|
559
|
+
rootOptionVisibility?: Partial<Record<keyof RootOptionsShape, boolean>>;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Create a configured get-dotenv CLI host.
|
|
563
|
+
* Applies defaults, installs root hooks, and composes plugins.
|
|
564
|
+
* Returns a runner function that accepts an argv array.
|
|
565
|
+
*/
|
|
566
|
+
declare function createCli(opts?: CreateCliOptions): (argv?: string[]) => Promise<void>;
|
|
567
|
+
|
|
568
|
+
export { createCli };
|
|
569
|
+
export type { CreateCliOptions };
|