Skip to content

Commit 12664f3

Browse files
feat(command-env): add support for plaintext output in env:list (#5322)
* feat(command-env): add support for plaintext output in env:list * fix: prevent conflict in plaintext and json output flags Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 0bc18bb commit 12664f3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

docs/commands/env.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ netlify env:list
135135
**Flags**
136136

137137
- `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev")
138+
- `plain` (*boolean*) - Output environment variables as plaintext
138139
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
139140
- `debug` (*boolean*) - Print debugging information
140141
- `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
147148
netlify env:list --context production
148149
netlify env:list --context branch:staging
149150
netlify env:list --scope functions
151+
netlify env:list --plain
150152
```
151153

152154
---

src/commands/env/env-list.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ const envList = async (options, command) => {
7676
return false
7777
}
7878

79+
if (options.plain) {
80+
const plaintext = Object.entries(environment)
81+
.map(([key, variable]) => `${key}=${variable.value}`)
82+
.join('\n')
83+
log(plaintext)
84+
return false
85+
}
86+
7987
const forSite = `for site ${chalk.green(siteInfo.name)}`
8088
const contextType = AVAILABLE_CONTEXTS.includes(context) ? 'context' : 'branch'
8189
const withContext = isUsingEnvelope ? `in the ${chalk.magenta(options.context)} ${contextType}` : ''
@@ -126,6 +134,7 @@ export const createEnvListCommand = (program) =>
126134
normalizeContext,
127135
'dev',
128136
)
137+
.addOption(new Option('--plain', 'Output environment variables as plaintext').conflicts('json'))
129138
.addOption(
130139
new Option('-s, --scope <scope>', 'Specify a scope')
131140
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
@@ -136,6 +145,7 @@ export const createEnvListCommand = (program) =>
136145
'netlify env:list --context production',
137146
'netlify env:list --context branch:staging',
138147
'netlify env:list --scope functions',
148+
'netlify env:list --plain',
139149
])
140150
.description('Lists resolved environment variables for site (includes netlify.toml)')
141151
.action(async (options, command) => {

0 commit comments

Comments
 (0)