From 4e668f252ef3011e1a08ee5826f30423256be000 Mon Sep 17 00:00:00 2001 From: Dylan Spyer <115838205+dylanspyer@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:18:23 -0600 Subject: [PATCH] feat: implemented flag conflicts in `deploy.ts` (#6909) Implemented feature from `commander` to prevent mutually exclusive flags from being run in the same command. Co-authored-by: Ben Hancock Co-authored-by: Sarah Etter --- src/commands/deploy/index.ts | 13 ++++++++++--- .../integration/commands/deploy/deploy.test.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/commands/deploy/index.ts b/src/commands/deploy/index.ts index e5c59a4bde9..acb8be55edb 100644 --- a/src/commands/deploy/index.ts +++ b/src/commands/deploy/index.ts @@ -79,14 +79,17 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co ) .option('-d, --dir ', 'Specify a folder to deploy') .option('-f, --functions ', '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( @@ -103,7 +106,11 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co .option('-s, --site ', 'A site name or ID to deploy to', env.NETLIFY_SITE_ID) .option('--json', 'Output deployment data as JSON') .option('--timeout ', '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 to use when resolving build configuration') .option( diff --git a/tests/integration/commands/deploy/deploy.test.ts b/tests/integration/commands/deploy/deploy.test.ts index 4e760b37710..abf1380e2c9 100644 --- a/tests/integration/commands/deploy/deploy.test.ts +++ b/tests/integration/commands/deploy/deploy.test.ts @@ -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' @@ -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, + ) + } + }) + }) })