Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/commands/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ netlify env:get
**Flags**

- `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev")
- `scope` (*builds | functions | post_processing | runtime | any*) - Specify a scope
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
- `debug` (*boolean*) - Print debugging information
- `httpProxy` (*string*) - Proxy server address to route requests through.
- `httpProxyCertificateFilename` (*string*) - Certificate file to use when connecting using a proxy server
Expand Down Expand Up @@ -135,7 +135,7 @@ netlify env:list
**Flags**

- `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev")
- `scope` (*builds | functions | post_processing | runtime | any*) - Specify a scope
- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope
- `debug` (*boolean*) - Print debugging information
- `httpProxy` (*string*) - Proxy server address to route requests through.
- `httpProxyCertificateFilename` (*string*) - Certificate file to use when connecting using a proxy server
Expand Down Expand Up @@ -168,7 +168,7 @@ netlify env:set
**Flags**

- `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") (default: all contexts)
- `scope` (*builds | functions | post_processing | runtime*) - Specify a scope (default: all scopes)
- `scope` (*builds | functions | post-processing | runtime*) - Specify a scope (default: all scopes)
- `debug` (*boolean*) - Print debugging information
- `httpProxy` (*string*) - Proxy server address to route requests through.
- `httpProxyCertificateFilename` (*string*) - Certificate file to use when connecting using a proxy server
Expand Down
2 changes: 1 addition & 1 deletion src/commands/env/env-get.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const createEnvGetCommand = (program) =>
)
.addOption(
new Option('-s, --scope <scope>', 'Specify a scope')
.choices(['builds', 'functions', 'post_processing', 'runtime', 'any'])
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
.default('any'),
)
.addExamples([
Expand Down
2 changes: 1 addition & 1 deletion src/commands/env/env-list.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const createEnvListCommand = (program) =>
)
.addOption(
new Option('-s, --scope <scope>', 'Specify a scope')
.choices(['builds', 'functions', 'post_processing', 'runtime', 'any'])
.choices(['builds', 'functions', 'post-processing', 'runtime', 'any'])
.default('any'),
)
.addExamples([
Expand Down
2 changes: 1 addition & 1 deletion src/commands/env/env-set.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const createEnvSetCommand = (program) =>
new Option('-s, --scope <scope...>', 'Specify a scope (default: all scopes)').choices([
'builds',
'functions',
'post_processing',
'post-processing',
'runtime',
]),
)
Expand Down
16 changes: 9 additions & 7 deletions src/utils/env/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'an
const configFileEnv = filterEnvBySource(env, 'configFile')

// filter out configFile env vars if a non-configFile scope is passed
const includeConfigEnvVars = ['any', 'builds', 'post_processing'].includes(scope)
const includeConfigEnvVars = /any|builds|post[-_]processing/.test(scope)

// Sources of environment variables, in ascending order of precedence.
return {
Expand All @@ -168,11 +168,13 @@ const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'an
* @returns {string} A human-readable, comma-separated list of scopes
*/
const getHumanReadableScopes = (scopes) => {
const HUMAN_SCOPES = {
builds: 'Builds',
functions: 'Functions',
post_processing: 'Post processing',
runtime: 'Runtime',
const HUMAN_SCOPES = ['Builds', 'Functions', 'Runtime', 'Post processing']
const SCOPES_MAP = {
builds: HUMAN_SCOPES[0],
functions: HUMAN_SCOPES[1],
runtime: HUMAN_SCOPES[2],
post_processing: HUMAN_SCOPES[3],
'post-processing': HUMAN_SCOPES[3],
}
if (!scopes) {
// if `scopes` is not available, the env var comes from netlify.toml
Expand All @@ -183,7 +185,7 @@ const getHumanReadableScopes = (scopes) => {
// shorthand instead of listing every available scope
return 'All'
}
return scopes.map((scope) => HUMAN_SCOPES[scope]).join(', ')
return scopes.map((scope) => SCOPES_MAP[scope]).join(', ')
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/650.command.envelope.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ test('env:set --scope should set the scope of an existing env var without needin

await withMockApi(routes, async ({ apiUrl, requests }) => {
const cliResponse = await callCli(
['env:set', 'EXISTING_VAR', '--scope', 'runtime', 'post_processing', '--json'],
['env:set', 'EXISTING_VAR', '--scope', 'runtime', 'post-processing', '--json'],
getCLIOptions({ builder, apiUrl }),
true,
)
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/utils/env/index.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ test('should convert scope keys into a human-readable list', (t) => {
t.is(getHumanReadableScopes([]), '')
t.is(getHumanReadableScopes(), 'Builds, Post processing')
t.is(getHumanReadableScopes(['post_processing']), 'Post processing')
t.is(getHumanReadableScopes(['post-processing']), 'Post processing')
t.is(getHumanReadableScopes(['builds', 'functions']), 'Builds, Functions')
t.is(getHumanReadableScopes(['builds', 'functions', 'runtime', 'post_processing']), 'All')
t.is(getHumanReadableScopes(['builds', 'functions', 'runtime', 'post-processing']), 'All')
})

test('should normalize a branch name or context', (t) => {
Expand Down