Skip to content

Commit

Permalink
feat: implemented flag conflicts in deploy.ts (#6909)
Browse files Browse the repository at this point in the history
Implemented feature from `commander` to prevent
mutually exclusive flags from being run in the same
command.

Co-authored-by: Ben Hancock <[email protected]>
Co-authored-by: Sarah Etter <[email protected]>
  • Loading branch information
3 people authored Nov 27, 2024
1 parent e9dc383 commit 4e668f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
)
.option('-d, --dir <path>', 'Specify a folder to deploy')
.option('-f, --functions <folder>', 'Specify a functions folder to deploy')
.option('-p, --prod', 'Deploy to production', false)
.addOption(
new Option('-p, --prod', 'Deploy to production').default(false).conflicts(['alias', 'branch', 'prodIfUnlocked']),
)
.addOption(
new Option(
'--prodIfUnlocked',
'Old, prefer --prod-if-unlocked. Deploy to production if unlocked, create a draft otherwise',
)
.default(false)
.hideHelp(true),
.hideHelp(true)
.conflicts(['alias', 'branch', 'prod']),
)
.option('--prod-if-unlocked', 'Deploy to production if unlocked, create a draft otherwise', false)
.option(
Expand All @@ -103,7 +106,11 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
.option('-s, --site <name-or-id>', 'A site name or ID to deploy to', env.NETLIFY_SITE_ID)
.option('--json', 'Output deployment data as JSON')
.option('--timeout <number>', 'Timeout to wait for deployment to finish', (value) => Number.parseInt(value))
.option('--trigger', 'Trigger a new build of your site on Netlify without uploading local files')
.addOption(
new Option('--trigger', 'Trigger a new build of your site on Netlify without uploading local files').conflicts(
'build',
),
)
.option('--build', 'Run build command before deploying')
.option('--context <context>', 'Context to use when resolving build configuration')
.option(
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/commands/deploy/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import fetch from 'node-fetch'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'

import { callCli } from '../../utils/call-cli.js'
import { cliPath } from '../../utils/cli-path.js'
import { createLiveTestSite, generateSiteName } from '../../utils/create-live-test-site.js'
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
import { pause } from '../../utils/pause.js'
Expand Down Expand Up @@ -1040,4 +1041,20 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
},
)
})

test('should not run deploy with conflicting flags', async (t) => {
await withSiteBuilder(t, async (builder) => {
await builder.build()
try {
await callCli(['deploy', '--prodIfUnlocked', '--prod'], {
cwd: builder.directory,
env: { NETLIFY_SITE_ID: context.siteId },
})
} catch (error) {
expect(error.stderr.includes(`Error: option '-p, --prod' cannot be used with option '--prodIfUnlocked`)).toBe(
true,
)
}
})
})
})

0 comments on commit 4e668f2

Please sign in to comment.