Skip to content

Commit 234c596

Browse files
fix: throw deploy error when missing required params (#150)
* fix: throw deploy error when missing required params * chore: comma separate values Co-authored-by: Willie Ruemmele <[email protected]>
1 parent 95739bf commit 234c596

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

messages/deploy.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"validateDeployRequestId": "deploy request ID of the validated deployment to run a Quick Deploy",
2828
"soapDeploy": "deploy metadata with SOAP API instead of REST API"
2929
},
30+
"MissingRequiredParam": "Missing one of the following parameters: %s",
3031
"checkOnlySuccess": "Successfully validated the deployment. %s components deployed and %s tests run.\nUse the --verbose parameter to see detailed output.",
3132
"MissingDeployId": "No deploy ID was provided or found in deploy history",
3233
"deployCanceled": "The deployment has been canceled by %s",

src/commands/force/source/deploy.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as os from 'os';
88
import { flags, FlagsConfig } from '@salesforce/command';
9-
import { Messages } from '@salesforce/core';
9+
import { Messages, SfdxError } from '@salesforce/core';
1010
import { AsyncResult, DeployResult } from '@salesforce/source-deploy-retrieve';
1111
import { Duration } from '@salesforce/kit';
1212
import { getString, isString } from '@salesforce/ts-types';
@@ -23,6 +23,9 @@ import { DeployProgressStatusFormatter } from '../../../formatters/deployProgres
2323
Messages.importMessagesDirectory(__dirname);
2424
const messages = Messages.loadMessages('@salesforce/plugin-source', 'deploy');
2525

26+
// One of these flags must be specified for a valid deploy.
27+
const requiredFlags = ['manifest', 'metadata', 'sourcepath', 'validateddeployrequestid'];
28+
2629
type TestLevel = 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg';
2730

2831
export class Deploy extends DeployCommand {
@@ -109,6 +112,11 @@ export class Deploy extends DeployCommand {
109112
});
110113

111114
public async run(): Promise<DeployCommandResult | DeployCommandAsyncResult> {
115+
// verify that the user defined one of: manifest, metadata, sourcepath, validateddeployrequestid
116+
if (!Object.keys(this.flags).some((flag) => requiredFlags.includes(flag))) {
117+
throw SfdxError.create('@salesforce/plugin-source', 'deploy', 'MissingRequiredParam', [requiredFlags.join(', ')]);
118+
}
119+
112120
await this.deploy();
113121
this.resolveSuccess();
114122
return this.formatResult();

test/commands/source/deploy.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as sinon from 'sinon';
1010
import { expect } from 'chai';
1111
import { MetadataApiDeployOptions } from '@salesforce/source-deploy-retrieve';
1212
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
13-
import { ConfigAggregator, Lifecycle, Org, SfdxProject } from '@salesforce/core';
13+
import { ConfigAggregator, Lifecycle, Org, SfdxProject, Messages } from '@salesforce/core';
1414
import { UX } from '@salesforce/command';
1515
import { IConfig } from '@oclif/config';
1616
import { Deploy } from '../../../src/commands/force/source/deploy';
@@ -24,6 +24,10 @@ import { DeployProgressBarFormatter } from '../../../src/formatters/deployProgre
2424
import { DeployProgressStatusFormatter } from '../../../src/formatters/deployProgressStatusFormatter';
2525
import { getDeployResult } from './deployResponses';
2626
import { exampleSourceComponent } from './testConsts';
27+
28+
Messages.importMessagesDirectory(__dirname);
29+
const messages = Messages.loadMessages('@salesforce/plugin-source', 'deploy');
30+
2731
describe('force:source:deploy', () => {
2832
const sandbox = sinon.createSandbox();
2933
const username = '[email protected]';
@@ -177,6 +181,15 @@ describe('force:source:deploy', () => {
177181
expect(initProgressBarStub.callCount).to.equal(callCount);
178182
};
179183

184+
it('should error if sourcepath or manifest arguments are not provided', async () => {
185+
const requiredFlags = 'manifest, metadata, sourcepath, validateddeployrequestid';
186+
try {
187+
await runDeployCmd([]);
188+
} catch (e) {
189+
expect((e as Error).message).to.equal(messages.getMessage('MissingRequiredParam', [requiredFlags]));
190+
}
191+
});
192+
180193
it('should pass along sourcepath', async () => {
181194
const sourcepath = ['somepath'];
182195
const result = await runDeployCmd(['--sourcepath', sourcepath[0], '--json']);

0 commit comments

Comments
 (0)