diff --git a/docs/commands/env.md b/docs/commands/env.md index cf25d48b0a4..a38da1edd65 100644 --- a/docs/commands/env.md +++ b/docs/commands/env.md @@ -135,6 +135,7 @@ netlify env:list **Flags** - `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") +- `plain` (*boolean*) - Output environment variables as plaintext - `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope - `debug` (*boolean*) - Print debugging information - `httpProxy` (*string*) - Proxy server address to route requests through. @@ -147,6 +148,7 @@ netlify env:list # list variables with values in the dev context and with any sc netlify env:list --context production netlify env:list --context branch:staging netlify env:list --scope functions +netlify env:list --plain ``` --- diff --git a/src/commands/env/env-list.mjs b/src/commands/env/env-list.mjs index 545eeede855..2200deb09bb 100644 --- a/src/commands/env/env-list.mjs +++ b/src/commands/env/env-list.mjs @@ -76,6 +76,14 @@ const envList = async (options, command) => { return false } + if (options.plain) { + const plaintext = Object.entries(environment) + .map(([key, variable]) => `${key}=${variable.value}`) + .join('\n') + log(plaintext) + return false + } + const forSite = `for site ${chalk.green(siteInfo.name)}` const contextType = AVAILABLE_CONTEXTS.includes(context) ? 'context' : 'branch' const withContext = isUsingEnvelope ? `in the ${chalk.magenta(options.context)} ${contextType}` : '' @@ -126,6 +134,7 @@ export const createEnvListCommand = (program) => normalizeContext, 'dev', ) + .addOption(new Option('--plain', 'Output environment variables as plaintext').conflicts('json')) .addOption( new Option('-s, --scope ', 'Specify a scope') .choices(['builds', 'functions', 'post-processing', 'runtime', 'any']) @@ -136,6 +145,7 @@ export const createEnvListCommand = (program) => 'netlify env:list --context production', 'netlify env:list --context branch:staging', 'netlify env:list --scope functions', + 'netlify env:list --plain', ]) .description('Lists resolved environment variables for site (includes netlify.toml)') .action(async (options, command) => {