Skip to content

Commit c7fae0c

Browse files
committed
feat: add kebab-case options to cli flags - first example
1 parent 83510e4 commit c7fae0c

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/commands/addons/addons.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const createAddonsCommand = (program) => {
3030
.command('addons')
3131
.alias('addon')
3232
.description('(Beta) Manage Netlify Add-ons')
33-
.noHelpOptions()
3433
.addExamples([
3534
'netlify addons:create addon-xyz',
3635
'netlify addons:list',

src/commands/base-command.mjs

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import {
2525
} from '../utils/command-helpers.mjs'
2626
import getGlobalConfig from '../utils/get-global-config.mjs'
2727
import openBrowser from '../utils/open-browser.mjs'
28+
import {
29+
warnForDeprecatedOptions,
30+
deprecatedArgParser,
31+
returnDeprecatedOptionValue,
32+
} from '../utils/option-deprecation.mjs'
2833
import StateConfig from '../utils/state-config.mjs'
2934
import { identify, track } from '../utils/telemetry/index.mjs'
3035

@@ -99,13 +104,19 @@ export default class BaseCommand extends Command {
99104
.addOption(new Option('--cwd <cwd>').hideHelp(true))
100105
.addOption(new Option('-o, --offline').hideHelp(true))
101106
.addOption(new Option('--auth <token>', 'Netlify auth token').hideHelp(true))
107+
.addOption(
108+
new Option('--httpProxy [address]', '[DEPRECATED IN V13] Proxy server address to route requests through.')
109+
.default(process.env.HTTP_PROXY || process.env.HTTPS_PROXY)
110+
.hideHelp(true)
111+
.argParser(deprecatedArgParser),
112+
)
102113
.option(
103114
'--httpProxyCertificateFilename [file]',
104115
'Certificate file to use when connecting using a proxy server',
105116
process.env.NETLIFY_PROXY_CERTIFICATE_FILENAME,
106117
)
107118
.option(
108-
'--httpProxy [address]',
119+
'--http-proxy [address]',
109120
'Proxy server address to route requests through.',
110121
process.env.HTTP_PROXY || process.env.HTTPS_PROXY,
111122
)
@@ -117,6 +128,11 @@ export default class BaseCommand extends Command {
117128
await this.init(actionCommand)
118129
debug(`${name}:preAction`)('end')
119130
})
131+
.hook('preAction', (parentCommand) => {
132+
const options = parentCommand.opts()
133+
if (!options) return
134+
warnForDeprecatedOptions(options)
135+
})
120136
)
121137
}
122138

@@ -420,7 +436,7 @@ export default class BaseCommand extends Command {
420436
const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig
421437
const normalizedConfig = normalizeConfig(config)
422438
const agent = await getAgent({
423-
httpProxy: options.httpProxy,
439+
httpProxy: returnDeprecatedOptionValue(options.httpProxy),
424440
certificateFile: options.httpProxyCertificateFilename,
425441
})
426442
const apiOpts = { ...apiUrlOpts, agent }

src/utils/option-deprecation.mjs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { chalk, log, NETLIFYDEVWARN } from './command-helpers.mjs'
2+
3+
// This file contains logic for flags in camelcase that will be deprecated in v13 and replaced in kebab-case.
4+
// Flags to be deprecated in v13
5+
const DEPRECATED_OPTIONS = {
6+
httpProxy: { option: '--httpProxy', newOption: '--http-proxy', deprecatedVersion: 'v13' },
7+
}
8+
9+
// TODO v13: remove all options that use this function
10+
export const deprecatedArgParser = (value) => ({
11+
value,
12+
deprecationWarn: true,
13+
})
14+
15+
// TODO v13: remove all uses of this function in the code so they can fall back on just using `option` instead of `option.value`
16+
export const returnDeprecatedOptionValue = (option) => (option.value ? option.value : option)
17+
18+
export const warnForDeprecatedOptions = (options) => {
19+
Object.entries(options).forEach(([option, value]) => {
20+
const deprecatedOption = DEPRECATED_OPTIONS[option]
21+
22+
if (value.deprecationWarn && deprecatedOption) {
23+
log(
24+
NETLIFYDEVWARN,
25+
chalk.yellowBright(
26+
`The flag ${deprecatedOption.option} is replaced by ${deprecatedOption.newOption} and will be deprecated in ${deprecatedOption.deprecatedVersion}`,
27+
),
28+
)
29+
}
30+
})
31+
}

0 commit comments

Comments
 (0)