generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mdapi:deploy:cancel command, refactor base classes to suppo…
…rt MDAPI and SOURCE stash keys (#301) * fix: add mdapi:deploy:cancel command, refactor base classes to support MDAPI and SOURCE stash keys * chore: remove helpers from kit * chore: address QA issues
- Loading branch information
1 parent
25beb65
commit 9dcc3e7
Showing
15 changed files
with
382 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"description": "cancel a metadata deployment \n Use this command to cancel a specified asynchronous metadata deployment. You can also specify a wait time (in minutes) to check for updates to the canceled deploy status.", | ||
"longDescription": "Cancels an asynchronous metadata deployment.", | ||
"flags": { | ||
"wait": "wait time for command to finish in minutes", | ||
"waitLong": "Number of minutes to wait for the command to complete and display results to the terminal window. If the command continues to run after the wait period, the CLI returns control of the terminal window to you. The default is 33 minutes.", | ||
"jobid": "job ID of the deployment you want to cancel; defaults to your most recent CLI deployment if not specified" | ||
}, | ||
|
||
"examples": [ | ||
"Deploy a directory of files to the org", | ||
" $ sfdx force:mdapi:deploy -d <directory>", | ||
"Now cancel this deployment and wait two minutes", | ||
" $ sfdx force:mdapi:deploy:cancel -w 2", | ||
"If you have multiple deployments in progress and want to cancel a specific one, specify the job ID", | ||
" $ sfdx force:mdapi:deploy:cancel -i <jobid>", | ||
"Check the status of the cancel job", | ||
" $ sfdx force:mdapi:deploy:report" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as os from 'os'; | ||
import { flags, FlagsConfig } from '@salesforce/command'; | ||
import { Messages, SfdxError } from '@salesforce/core'; | ||
import { Duration } from '@salesforce/kit'; | ||
import { RequestStatus } from '@salesforce/source-deploy-retrieve'; | ||
import { DeployCommand } from '../../../../deployCommand'; | ||
import { | ||
DeployCancelCommandResult, | ||
DeployCancelResultFormatter, | ||
} from '../../../../formatters/deployCancelResultFormatter'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-source', 'md.cancel'); | ||
|
||
export class Cancel extends DeployCommand { | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessage('examples').split(os.EOL); | ||
public static readonly requiresUsername = true; | ||
public static readonly flagsConfig: FlagsConfig = { | ||
wait: flags.minutes({ | ||
char: 'w', | ||
default: Duration.minutes(DeployCommand.DEFAULT_WAIT_MINUTES), | ||
min: Duration.minutes(1), | ||
description: messages.getMessage('flags.wait'), | ||
longDescription: messages.getMessage('flags.waitLong'), | ||
}), | ||
jobid: flags.id({ | ||
char: 'i', | ||
description: messages.getMessage('flags.jobid'), | ||
validate: (val) => { | ||
if (val.startsWith('0Af')) { | ||
return true; | ||
} else { | ||
throw SfdxError.create('@salesforce/plugin-source', 'deploy', 'invalidDeployId'); | ||
} | ||
}, | ||
}), | ||
}; | ||
// The most important difference between this and source:deploy:cancel | ||
public isSourceStash = false; | ||
|
||
public async run(): Promise<DeployCancelCommandResult> { | ||
await this.cancel(); | ||
this.resolveSuccess(); | ||
return this.formatResult(); | ||
} | ||
|
||
protected async cancel(): Promise<void> { | ||
const deployId = this.resolveDeployId(this.getFlag<string>('jobid')); | ||
try { | ||
const deploy = this.createDeploy(deployId); | ||
await deploy.cancel(); | ||
|
||
this.deployResult = await this.poll(deployId); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
throw SfdxError.create('@salesforce/plugin-source', 'cancel', 'CancelFailed', [e.message]); | ||
} else { | ||
throw SfdxError.wrap(e); | ||
} | ||
} | ||
} | ||
|
||
protected resolveSuccess(): void { | ||
const status = this.deployResult.response.status; | ||
if (status !== RequestStatus.Canceled) { | ||
this.setExitCode(1); | ||
} | ||
} | ||
|
||
protected formatResult(): DeployCancelCommandResult { | ||
const formatter = new DeployCancelResultFormatter(this.logger, this.ux, this.deployResult); | ||
if (!this.isJsonOutput()) { | ||
formatter.display(); | ||
} | ||
return formatter.getJson(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.