-
Notifications
You must be signed in to change notification settings - Fork 53
/
flags.js
181 lines (172 loc) · 4.97 KB
/
flags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import process from 'process'
import filterObj from 'filter-obj'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import { normalizeCliFeatureFlags } from '../options/feature_flags.js'
// Parse CLI flags
export const parseFlags = function () {
const { featureFlags: cliFeatureFlags = '', ...flags } = yargs(hideBin(process.argv))
.options(FLAGS)
.usage(USAGE)
.parse()
const featureFlags = normalizeCliFeatureFlags(cliFeatureFlags)
const flagsA = { ...flags, featureFlags }
const flagsB = filterObj(flagsA, isUserFlag)
return flagsB
}
const jsonParse = function (value) {
return value === undefined ? undefined : JSON.parse(value)
}
// List of CLI flags
const FLAGS = {
config: {
string: true,
describe: `Path to the configuration file.
Defaults to any netlify.toml in the git repository root directory or the base directory`,
},
defaultConfig: {
string: true,
describe: `JSON configuration object containing default values.
Each configuration default value is used unless overriden through the main configuration file.
Default: none.`,
coerce: jsonParse,
hidden: true,
},
cachedConfig: {
string: true,
describe: `JSON configuration object returned by @netlify/config when --output=/ is used
or when using @netlify/config programmatically.
This is done as a performance optimization to cache the configuration loading logic.
Default: none.`,
coerce: jsonParse,
hidden: true,
},
cachedConfigPath: {
string: true,
describe: `File path to the JSON configuration object returned by @netlify/config
when --output=/path is used.
This is done as a performance optimization to cache the configuration loading logic.
Default: none.`,
hidden: true,
},
inlineConfig: {
string: true,
describe: `JSON configuration object overriding the configuration file and other settings.
Default: none.`,
coerce: jsonParse,
hidden: true,
},
configMutations: {
array: true,
describe: `Array of changes to apply to the configuration.
Each change must be an object with three properties:
- "keys": array of keys targetting the property to change
- "value": new value of that property
- "event": build event when this change was applied, e.g. "onPreBuild"
Default: empty array.`,
coerce: jsonParse,
hidden: true,
},
cwd: {
string: true,
describe: `Current directory. Used to retrieve the configuration file.
Default: current directory`,
},
repositoryRoot: {
string: true,
describe: `Git repository root directory. Used to retrieve the configuration file.
Default: automatically guessed`,
},
output: {
string: true,
describe: `Where to output the JSON result.
Default: "-" (stdout)`,
},
stable: {
boolean: true,
describe: `Sort keys printed in the output.
Default: false`,
default: false,
},
token: {
string: true,
describe: `Netlify API token for authentication.
The NETLIFY_AUTH_TOKEN environment variable can be used as well.`,
},
host: {
string: true,
describe: `Host of the Netlify API.`,
hidden: true,
},
scheme: {
string: true,
describe: `Scheme/protocol of the Netlify API.`,
hidden: true,
},
pathPrefix: {
string: true,
describe: `Base path prefix of the Netlify API.`,
hidden: true,
},
siteId: {
string: true,
describe: `Netlify Site ID.`,
},
context: {
string: true,
describe: `Build context.
Default: 'production'`,
},
branch: {
string: true,
describe: `Repository branch.
Default: automatically guessed`,
},
baseRelDir: {
boolean: true,
describe: `Feature flag meant for backward compatibility.
When enabled, if the 'build.base' configuration property is defined, it is used
to try to retrieve a second configuration file and discard the first one.
Default: true`,
hidden: true,
},
mode: {
string: true,
describe: `Environment in which this is loaded. Can be:
- 'buildbot': within Netlify Buildbot
- 'cli': within Netlify CLI
- 'require': through import('@netlify/config')`,
hidden: true,
},
debug: {
boolean: true,
describe: 'Print debugging information',
hidden: true,
},
testOpts: {
describe: 'Options for testing only',
hidden: true,
},
featureFlags: {
describe: 'Comma-separated list of feature flags to enable unreleased features',
hidden: true,
},
offline: {
boolean: true,
describe: `Do not send requests to the Netlify API to retrieve site settings.
Default: false`,
},
buffer: {
boolean: true,
describe: 'Buffer output instead of streaming it',
hidden: true,
},
}
const USAGE = `netlify-config [OPTIONS...]
Retrieve and resolve the Netlify configuration.
The result is printed as a JSON object on stdout.`
// Remove `yargs`-specific options, shortcuts, dash-cased and aliases
const isUserFlag = function (key, value) {
return value !== undefined && !INTERNAL_KEYS.has(key) && key.length !== 1 && !key.includes('-')
}
const INTERNAL_KEYS = new Set(['help', 'version', '_', '$0'])