Skip to content

Commit 3bdd342

Browse files
committed
fix: avoid redefining --json option in commands
See tj/commander.js#2055.
1 parent 19d3794 commit 3bdd342

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

src/commands/base-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default class BaseCommand extends Command {
190190
.addOption(new Option('--json', 'Output return values as JSON').hideHelp(true))
191191
.addOption(new Option('--silent', 'Silence CLI output').hideHelp(true))
192192
.addOption(new Option('--cwd <cwd>').hideHelp(true))
193-
.addOption(new Option('-o, --offline').hideHelp(true))
193+
.addOption(new Option('-o, --offline').default(false).hideHelp(true))
194194
.addOption(new Option('--auth <token>', 'Netlify auth token').hideHelp(true))
195195
.addOption(
196196
new Option(

src/commands/blobs/blobs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OptionValues } from 'commander'
1+
import { Option, OptionValues } from 'commander'
22

33
import requiresSiteInfo from '../../utils/hooks/requires-site-info.js'
44
import BaseCommand from '../base-command.js'
@@ -53,7 +53,8 @@ export const createBlobsCommand = (program: BaseCommand) => {
5353
'-p, --prefix <prefix>',
5454
`A string for filtering down the entries; when specified, only the entries whose key starts with that prefix are returned`,
5555
)
56-
.option('--json', `Output list contents as JSON`)
56+
// The BaseCommand defines a `--json` option which is hidden from the help by default
57+
.addHelpOption(new Option('--json', 'Output list contents as JSON'))
5758
.alias('blob:list')
5859
.hook('preAction', requiresSiteInfo)
5960
.action(async (storeName: string, options: OptionValues, command: BaseCommand) => {

src/commands/build/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import process from 'process'
22

33
import { normalizeContext } from '../../utils/env/index.js'
44
import BaseCommand from '../base-command.js'
5+
import { Option } from 'commander'
56

67
export const createBuildCommand = (program: BaseCommand) =>
78
program
@@ -14,7 +15,7 @@ export const createBuildCommand = (program: BaseCommand) =>
1415
process.env.CONTEXT || 'production',
1516
)
1617
.option('--dry', 'Dry run: show instructions without running them', false)
17-
.option('-o, --offline', 'disables any features that require network access', false)
18+
.addHelpOption(new Option('-o, --offline', 'Disables any features that require network access'))
1819
.addExamples(['netlify build'])
1920
.action(async (options, command) => {
2021
const { build } = await import('./build.js')

src/commands/dev/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export const createDevCommand = (program: BaseCommand) => {
277277
.option('--framework <name>', 'framework to use. Defaults to #auto which automatically detects a framework')
278278
.option('-d ,--dir <path>', 'dir with static files')
279279
.option('-f ,--functions <folder>', 'specify a functions folder to serve')
280-
.option('-o ,--offline', 'disables any features that require network access')
280+
.addHelpOption(new Option('-o, --offline', 'Disables any features that require network access'))
281281
.addOption(
282282
new Option('--offline-env', 'disables fetching environment variables from the Netlify API').hideHelp(true),
283283
)

src/commands/functions/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OptionValues } from 'commander'
1+
import { Option, OptionValues } from 'commander'
22

33
import { chalk } from '../../utils/command-helpers.js'
44
import requiresSiteInfo from '../../utils/hooks/requires-site-info.js'
@@ -97,7 +97,7 @@ NOT the same as listing the functions that have been deployed. For that info you
9797
.description('Serve functions locally')
9898
.option('-f, --functions <dir>', 'Specify a functions directory to serve')
9999
.option('-p, --port <port>', 'Specify a port for the functions server', (value) => Number.parseInt(value))
100-
.option('-o, --offline', 'disables any features that require network access')
100+
.addHelpOption(new Option('-o, --offline', 'Disables any features that require network access'))
101101
.addHelpText('after', 'Helpful for debugging functions.')
102102
.action(async (options: OptionValues, command: BaseCommand) => {
103103
const { functionsServe } = await import('./functions-serve.js')

src/commands/serve/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const createServeCommand = (program: BaseCommand) =>
1818
.option('-p ,--port <port>', 'port of netlify dev', (value) => Number.parseInt(value))
1919
.option('-d ,--dir <path>', 'dir with static files')
2020
.option('-f ,--functions <folder>', 'specify a functions folder to serve')
21-
.option('-o ,--offline', 'disables any features that require network access')
21+
.addHelpOption(new Option('-o, --offline', 'Disables any features that require network access'))
2222
.addOption(
2323
new Option(
2424
'--internal-disable-edge-functions',

0 commit comments

Comments
 (0)