Skip to content

Commit

Permalink
feat(command-env): add support for plaintext output in env:list (#5322)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tinfoil-knight and kodiakhq[bot] authored Dec 21, 2022
1 parent 0bc18bb commit 12664f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/commands/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
```

---
Expand Down
10 changes: 10 additions & 0 deletions src/commands/env/env-list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''
Expand Down Expand Up @@ -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 <scope>', 'Specify a scope')
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
Expand All @@ -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) => {
Expand Down

1 comment on commit 12664f3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Package size: 249 MB

Please sign in to comment.