Execute a single command under the current dotenv context. Includes a convenient
parent‑level -c, --cmd <command...> alias so npm script flags apply to
getdotenv rather than the inner shell command.
// Recommended: plugins barrel (shares type identity with cliHost)
import { cmdPlugin } from '@karmaniverous/get-dotenv/plugins';
Per‑plugin subpaths remain available when needed:
import { cmdPlugin } from '@karmaniverous/get-dotenv/plugins/cmd';
getdotenv cmd [command...]
Positional tokens are joined into a single command string. The plugin resolves scripts and shell settings using shared helpers and executes the child with:
{ ...process.env, ...ctx.dotenv }stdio: inherits by default; enable capture with --capture or GETDOTENV_STDIO=pipeThe alias allows:
getdotenv -c 'echo $APP_SETTING'
Prefer the alias for npm scripts so flags after -- are routed to getdotenv:
{ "scripts": { "print": "getdotenv -c 'echo $APP_SETTING'" } }
Then:
npm run print -- -e dev
Conflict guard: Supplying both the alias and the cmd subcommand in the same
invocation is disallowed and exits with a helpful message.
$VAR to avoid outer‑shell expansion.-e/--eval as getdotenv’s --env.Examples:
getdotenv --cmd 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
getdotenv --shell-off cmd node -e "console.log(process.env.APP_SETTING ?? '')"
Use --trace [keys...] to print concise lines to stderr before spawning the
child, indicating the origin and value composition for each key. Useful in CI
and for debugging overlays.
Commands may resolve via scripts[name], and scripts[name].shell (boolean or
string) overrides the global shell for that script:
{
"scripts": {
"bash-only": { "cmd": "echo $SHELL && echo OK", "shell": "/bin/bash" },
"plain": { "cmd": "node -v", "shell": false }
}
}
Then:
getdotenv cmd bash-only
getdotenv cmd plain