Skip to content

feat: add kebab-case options to cli flags #5395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion src/commands/addons/addons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const createAddonsCommand = (program) => {
.command('addons')
.alias('addon')
.description('(Beta) Manage Netlify Add-ons')
.noHelpOptions()
.addExamples([
'netlify addons:create addon-xyz',
'netlify addons:list',
Expand Down
20 changes: 18 additions & 2 deletions src/commands/base-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
} from '../utils/command-helpers.mjs'
import getGlobalConfig from '../utils/get-global-config.mjs'
import openBrowser from '../utils/open-browser.mjs'
import {
warnForDeprecatedOptions,
deprecatedArgParser,
returnDeprecatedOptionValue,
} from '../utils/option-deprecation.mjs'
import StateConfig from '../utils/state-config.mjs'
import { identify, track } from '../utils/telemetry/index.mjs'

Expand Down Expand Up @@ -99,13 +104,19 @@ export default class BaseCommand extends Command {
.addOption(new Option('--cwd <cwd>').hideHelp(true))
.addOption(new Option('-o, --offline').hideHelp(true))
.addOption(new Option('--auth <token>', 'Netlify auth token').hideHelp(true))
.addOption(
new Option('--httpProxy [address]', '[DEPRECATED IN V13] Proxy server address to route requests through.')
.default(process.env.HTTP_PROXY || process.env.HTTPS_PROXY)
.hideHelp(true)
.argParser(deprecatedArgParser),
)
.option(
'--httpProxyCertificateFilename [file]',
'Certificate file to use when connecting using a proxy server',
process.env.NETLIFY_PROXY_CERTIFICATE_FILENAME,
)
.option(
'--httpProxy [address]',
'--http-proxy [address]',
'Proxy server address to route requests through.',
process.env.HTTP_PROXY || process.env.HTTPS_PROXY,
)
Expand All @@ -117,6 +128,11 @@ export default class BaseCommand extends Command {
await this.init(actionCommand)
debug(`${name}:preAction`)('end')
})
.hook('preAction', (parentCommand) => {
const options = parentCommand.opts()
if (!options) return
warnForDeprecatedOptions(options)
})
)
}

Expand Down Expand Up @@ -420,7 +436,7 @@ export default class BaseCommand extends Command {
const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig
const normalizedConfig = normalizeConfig(config)
const agent = await getAgent({
httpProxy: options.httpProxy,
httpProxy: returnDeprecatedOptionValue(options.httpProxy),
certificateFile: options.httpProxyCertificateFilename,
})
const apiOpts = { ...apiUrlOpts, agent }
Expand Down
31 changes: 31 additions & 0 deletions src/utils/option-deprecation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { chalk, log, NETLIFYDEVWARN } from './command-helpers.mjs'

// This file contains logic for flags in camelcase that will be deprecated in v13 and replaced in kebab-case.
// Flags to be deprecated in v13
const DEPRECATED_OPTIONS = {
httpProxy: { option: '--httpProxy', newOption: '--http-proxy', deprecatedVersion: 'v13' },
}

// TODO v13: remove all options that use this function
export const deprecatedArgParser = (value) => ({
value,
deprecationWarn: true,
})

// TODO v13: remove all uses of this function in the code so they can fall back on just using `option` instead of `option.value`
export const returnDeprecatedOptionValue = (option) => (option.value ? option.value : option)

export const warnForDeprecatedOptions = (options) => {
Object.entries(options).forEach(([option, value]) => {
const deprecatedOption = DEPRECATED_OPTIONS[option]

if (value.deprecationWarn && deprecatedOption) {
log(
NETLIFYDEVWARN,
chalk.yellowBright(
`The flag ${deprecatedOption.option} is replaced by ${deprecatedOption.newOption} and will be deprecated in ${deprecatedOption.deprecatedVersion}`,
),
)
}
})
}