Skip to content
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

feat: implemented flag conflicts in deploy.ts #6909

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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,
)
}
})
})
})
Loading