diff --git a/command-snapshot.json b/command-snapshot.json index d94d2122..3fbc8a91 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -27,8 +27,8 @@ "alias": ["force:org:snapshot:delete"], "command": "org:delete:snapshot", "flagAliases": ["apiversion", "targetdevhubusername"], - "flagChars": ["s", "v"], - "flags": ["api-version", "flags-dir", "json", "loglevel", "snapshot", "target-dev-hub"], + "flagChars": ["p", "s", "v"], + "flags": ["api-version", "flags-dir", "json", "loglevel", "no-prompt", "snapshot", "target-dev-hub"], "plugin": "@salesforce/plugin-signups" }, { diff --git a/messages/snapshot.delete.md b/messages/snapshot.delete.md index 5ab8536a..30dc441b 100644 --- a/messages/snapshot.delete.md +++ b/messages/snapshot.delete.md @@ -24,6 +24,14 @@ Name or ID of snapshot to delete. The IDs of scratch org snapshots start with 0Oo. +# flags.no-prompt.summary + +Don't prompt the user to confirm the deletion. + +# prompt.confirm + +Are you sure you want to delete the snapshot with name: %s? + # success Successfully deleted snapshot %s. diff --git a/src/commands/org/delete/snapshot.ts b/src/commands/org/delete/snapshot.ts index 7a8f1891..74fd0890 100644 --- a/src/commands/org/delete/snapshot.ts +++ b/src/commands/org/delete/snapshot.ts @@ -23,7 +23,7 @@ const messages = Messages.loadMessages('@salesforce/plugin-signups', 'snapshot.d // jsforce can return SaveError[] or never[] const isSaveError = (error: SaveError): error is SaveError => error.message !== undefined; -export class SnapshotDelete extends SfCommand { +export class SnapshotDelete extends SfCommand { public static readonly summary = messages.getMessage('summary'); public static readonly description = messages.getMessage('description'); public static readonly examples = messages.getMessages('examples'); @@ -41,11 +41,20 @@ export class SnapshotDelete extends SfCommand { description: messages.getMessage('flags.snapshot.description'), required: true, }), + 'no-prompt': Flags.boolean({ + char: 'p', + summary: messages.getMessage('flags.no-prompt.summary'), + }), }; - public async run(): Promise { - // resolve the query to an ID. This also verifies the snapshot exists in the org + public async run(): Promise { const { flags } = await this.parse(SnapshotDelete); + const snapshot = flags['snapshot']; + if (!flags['no-prompt'] && !(await this.confirm({ message: messages.getMessage('prompt.confirm', [snapshot]) }))) { + return; + } + + // resolve the query to an ID. This also verifies the snapshot exists in the org const conn = flags['target-dev-hub'].getConnection(flags['api-version']); const result = await queryByNameOrId(conn, flags.snapshot); const deleteResult = await conn.sobject('OrgSnapshot').delete(result.Id); diff --git a/test/nuts/snapshots.nut.ts b/test/nuts/snapshots.nut.ts index c794cc8a..7d7ed4f3 100644 --- a/test/nuts/snapshots.nut.ts +++ b/test/nuts/snapshots.nut.ts @@ -137,26 +137,26 @@ describe('snapshot commands', () => { expect(table).not.to.include('.000+0000'); }); - it('can delete a snapshot by id', () => { - execCmd(`force:org:snapshot:delete -s ${aliasSnapshot.Id} --json`, { + it('can delete a snapshot by id (no prompt)', () => { + execCmd(`force:org:snapshot:delete -s ${aliasSnapshot.Id} --json --no-prompt`, { ensureExitCode: 0, }); }); - it('can delete a snapshot by name', () => { - execCmd(`force:org:snapshot:delete -s ${orgIdSnapshot.SnapshotName} --json`, { + it('can delete a snapshot by name (no prompt)', () => { + execCmd(`force:org:snapshot:delete -s ${orgIdSnapshot.SnapshotName} --json --no-prompt`, { ensureExitCode: 0, }); }); - it('can delete the last snapshot by name', () => { - execCmd(`force:org:snapshot:delete -s ${usernameSnapshot.SnapshotName} --json`, { + it('can delete the last snapshot by name (no prompt)', () => { + execCmd(`force:org:snapshot:delete -s ${usernameSnapshot.SnapshotName} --json --no-prompt`, { ensureExitCode: 0, }); }); - it('fails at deleting the same snapshot twice', () => { - execCmd(`force:org:snapshot:delete -s ${usernameSnapshot.SnapshotName} --json`, { + it('fails at deleting the same snapshot twice (no prompt)', () => { + execCmd(`force:org:snapshot:delete -s ${usernameSnapshot.SnapshotName} --json --no-prompt`, { ensureExitCode: 1, }); });