|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, salesforce.com, inc. |
| 3 | + * All rights reserved. |
| 4 | + * Licensed under the BSD 3-Clause license. |
| 5 | + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
| 6 | + */ |
| 7 | + |
| 8 | +import * as os from 'os'; |
| 9 | +import { flags, FlagsConfig } from '@salesforce/command'; |
| 10 | +import { Messages } from '@salesforce/core'; |
| 11 | +import { DeployResult } from '@salesforce/source-deploy-retrieve'; |
| 12 | +import { Duration } from '@salesforce/kit'; |
| 13 | +import { asString } from '@salesforce/ts-types'; |
| 14 | +import { SourceCommand } from '../../../../sourceCommand'; |
| 15 | + |
| 16 | +Messages.importMessagesDirectory(__dirname); |
| 17 | +const messages = Messages.loadMessages('@salesforce/plugin-source', 'cancel'); |
| 18 | + |
| 19 | +export class Cancel extends SourceCommand { |
| 20 | + public static readonly description = messages.getMessage('description'); |
| 21 | + public static readonly examples = messages.getMessage('examples').split(os.EOL); |
| 22 | + public static readonly requiresUsername = true; |
| 23 | + public static readonly flagsConfig: FlagsConfig = { |
| 24 | + wait: flags.minutes({ |
| 25 | + char: 'w', |
| 26 | + default: Duration.minutes(SourceCommand.DEFAULT_SRC_WAIT_MINUTES), |
| 27 | + min: Duration.minutes(1), |
| 28 | + description: messages.getMessage('flags.wait'), |
| 29 | + }), |
| 30 | + jobid: flags.id({ |
| 31 | + char: 'i', |
| 32 | + description: messages.getMessage('flags.jobid'), |
| 33 | + }), |
| 34 | + }; |
| 35 | + |
| 36 | + public async run(): Promise<DeployResult> { |
| 37 | + let id = asString(this.flags.jobid); |
| 38 | + if (!id) { |
| 39 | + const stash = this.getConfig(); |
| 40 | + stash.readSync(); |
| 41 | + id = asString((stash.get(SourceCommand.STASH_KEY) as { jobid: string }).jobid); |
| 42 | + } |
| 43 | + |
| 44 | + // TODO: update to use SDRL we can just do this for now |
| 45 | + // this is the toolbelt implementation |
| 46 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment |
| 47 | + return (await this.org.getConnection().metadata['_invoke']('cancelDeploy', { |
| 48 | + id, |
| 49 | + })) as DeployResult; |
| 50 | + } |
| 51 | +} |
0 commit comments