generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: commands to delete scratch orgs and sandboxes
* feat: delete scratch org and sboxes * chore: snapshot * chore: hi, schema * refactor: specifc return type for sbox * chore: schema one more time * refactor: target-org * refactor: consolidate flags and confirmation-prompt * refactor: use new Flags from plugins-core * chore: bump dependencies * chore: merge deps * chore: bump deps for latest flag * test: fix typo * test: nuts without setting envs * fix: summary, not description * Update src/commands/env/delete/sandbox.ts Co-authored-by: Rodrigo Espinosa de los Monteros <[email protected]> * refactor: move confirm to sfCommand * test: ut fixes from env:create sbox branch * chore: dependency bumps * ci: tsconfig to build oclif/core from top-level * chore: bump plugins-core * test: copy open test from Pete's branch Co-authored-by: Rodrigo Espinosa de los Monteros <[email protected]>
- Loading branch information
Showing
16 changed files
with
913 additions
and
372 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
[ | ||
{ | ||
"command": "env:delete:sandbox", | ||
"plugin": "@salesforce/plugin-env", | ||
"flags": ["json", "no-prompt", "target-org"], | ||
"alias": [] | ||
}, | ||
{ | ||
"command": "env:delete:scratch", | ||
"plugin": "@salesforce/plugin-env", | ||
"flags": ["json", "no-prompt", "target-org"], | ||
"alias": [] | ||
}, | ||
{ | ||
"command": "env:display", | ||
"plugin": "@salesforce/plugin-env", | ||
"flags": ["json", "target-env"] | ||
"flags": ["json", "target-env"], | ||
"alias": [] | ||
}, | ||
{ | ||
"command": "env:list", | ||
"plugin": "@salesforce/plugin-env", | ||
"flags": ["all", "columns", "csv", "filter", "json", "no-header", "no-truncate", "output", "sort"] | ||
"flags": ["all", "columns", "csv", "filter", "json", "no-header", "no-truncate", "output", "sort"], | ||
"alias": [] | ||
}, | ||
{ | ||
"command": "env:open", | ||
"plugin": "@salesforce/plugin-env", | ||
"flags": ["browser", "json", "path", "target-env", "url-only"] | ||
"flags": ["browser", "json", "path", "target-env", "url-only"], | ||
"alias": [] | ||
} | ||
] |
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,37 @@ | ||
# summary | ||
|
||
Delete a sandbox. | ||
|
||
# description | ||
|
||
Specify an environment with either the username you used when you logged into the environment with "sf login", or the alias you gave the environment when you created it. Run "sf env list" to view all your environments and their aliases. | ||
|
||
# examples | ||
|
||
- Delete a sandbox with alias my-sandbox: | ||
|
||
<%= config.bin %> <%= command.id %> --target-org=my-sandbox | ||
|
||
- Specify a username instead of an alias: | ||
|
||
<%= config.bin %> <%= command.id %> --target-org=[email protected] | ||
|
||
- Delete the org without prompting to confirm : | ||
|
||
<%= config.bin %> <%= command.id %> --target-org=my-sandbox --no-prompt | ||
|
||
# flags.target-org.summary | ||
|
||
Environment alias or login user. | ||
|
||
# flags.no-prompt.summary | ||
|
||
Do not prompt the user to confirm the deletion | ||
|
||
# prompt.confirm | ||
|
||
Delete sandbox with name: %s? Are you sure? | ||
|
||
# success | ||
|
||
Successfully marked sandbox %s for deletion |
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,41 @@ | ||
# summary | ||
|
||
Delete a scratch org. | ||
|
||
# description | ||
|
||
Specify an environment with either the username you used when you logged into the environment with "sf login", or the alias you gave the environment when you created it. Run "sf env list" to view all your environments and their aliases. | ||
|
||
# examples | ||
|
||
- Delete a scratch org with alias my-scratch-org: | ||
|
||
<%= config.bin %> <%= command.id %> --target-org=my-scratch-org | ||
|
||
- Specify a username instead of an alias: | ||
|
||
<%= config.bin %> <%= command.id %> --target-org=[email protected] | ||
|
||
- Delete the org without prompting to confirm : | ||
|
||
<%= config.bin %> <%= command.id %> --target-org=my-scratch-org --no-prompt | ||
|
||
# flags.target-org.summary | ||
|
||
Org alias or login user. | ||
|
||
# flags.no-prompt.summary | ||
|
||
Do not prompt the user to confirm the deletion | ||
|
||
# prompt.confirm | ||
|
||
Enqueue scratch org with name: %s for deletion? Are you sure? | ||
|
||
# success | ||
|
||
Successfully marked scratch org %s for deletion. | ||
|
||
# success.Idempotent | ||
|
||
Successfully deleted scratch org %s. |
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,19 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/SandboxDeleteResponse", | ||
"definitions": { | ||
"SandboxDeleteResponse": { | ||
"type": "object", | ||
"properties": { | ||
"orgId": { | ||
"type": "string" | ||
}, | ||
"username": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["orgId", "username"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/ScratchDeleteResponse", | ||
"definitions": { | ||
"ScratchDeleteResponse": { | ||
"type": "object", | ||
"properties": { | ||
"orgId": { | ||
"type": "string" | ||
}, | ||
"username": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["orgId", "username"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
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,50 @@ | ||
/* | ||
* Copyright (c) 2021, 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 { Messages } from '@salesforce/core'; | ||
import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-env', 'delete_sandbox'); | ||
|
||
export interface SandboxDeleteResponse { | ||
orgId: string; | ||
username: string; | ||
} | ||
export default class EnvDeleteSandbox extends SfCommand<SandboxDeleteResponse> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
public static flags = { | ||
'target-org': Flags.requiredOrg({ | ||
summary: messages.getMessage('flags.target-org.summary'), | ||
}), | ||
'no-prompt': Flags.boolean({ | ||
char: 'p', | ||
summary: messages.getMessage('flags.no-prompt.summary'), | ||
}), | ||
}; | ||
|
||
public async run(): Promise<SandboxDeleteResponse> { | ||
const { flags } = await this.parse(EnvDeleteSandbox); | ||
const org = flags['target-org']; | ||
|
||
if (flags['no-prompt'] || (await this.confirm(messages.getMessage('prompt.confirm', [org.getUsername()])))) { | ||
try { | ||
await org.delete(); | ||
this.log(messages.getMessage('success', [org.getUsername()])); | ||
} catch (e) { | ||
if (e instanceof Error && e.name === 'SandboxNotFound') { | ||
this.log(messages.getMessage('success.Idempotent', [org.getUsername()])); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
return { username: org.getUsername(), orgId: org.getOrgId() }; | ||
} | ||
} | ||
} |
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,52 @@ | ||
/* | ||
* Copyright (c) 2021, 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 { Messages } from '@salesforce/core'; | ||
import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-env', 'delete_scratch'); | ||
|
||
export interface ScratchDeleteResponse { | ||
orgId: string; | ||
username: string; | ||
} | ||
|
||
export default class EnvDeleteScratch extends SfCommand<ScratchDeleteResponse> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
public static flags = { | ||
'target-org': Flags.requiredOrg({ | ||
summary: messages.getMessage('flags.target-org.summary'), | ||
}), | ||
'no-prompt': Flags.boolean({ | ||
char: 'p', | ||
summary: messages.getMessage('flags.no-prompt.summary'), | ||
}), | ||
}; | ||
|
||
public async run(): Promise<ScratchDeleteResponse> { | ||
const { flags } = await this.parse(EnvDeleteScratch); | ||
const org = flags['target-org']; | ||
|
||
if (flags['no-prompt'] || (await this.confirm(messages.getMessage('prompt.confirm', [org.getUsername()])))) { | ||
try { | ||
await org.delete(); | ||
this.log(messages.getMessage('success', [org.getUsername()])); | ||
} catch (e) { | ||
if (e instanceof Error && e.name === 'ScratchOrgNotFound') { | ||
this.log(messages.getMessage('success.Idempotent', [org.getUsername()])); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
return { username: org.getUsername(), orgId: org.getOrgId() }; | ||
} | ||
} | ||
} |
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,63 @@ | ||
/* | ||
* 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 fs from 'fs'; | ||
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; | ||
import { expect } from 'chai'; | ||
import { ScratchDeleteResponse } from '../../../../src/commands/env/delete/scratch'; | ||
|
||
describe('env delete scratch NUTs', () => { | ||
const scratchOrgAlias = 'scratch-org'; | ||
let session: TestSession; | ||
let scratchUsernames: string[]; | ||
before(async () => { | ||
session = await TestSession.create({ | ||
project: { | ||
name: 'testProject', | ||
}, | ||
setupCommands: [ | ||
`sfdx force:org:create -f config/project-scratch-def.json -d 1 -a ${scratchOrgAlias}`, | ||
'sfdx force:org:create -f config/project-scratch-def.json -d 1', | ||
'sfdx force:org:create -f config/project-scratch-def.json -d 1 -s', | ||
], | ||
}); | ||
scratchUsernames = (session.setup as Array<{ result: { username: string } }>).map((setup) => setup.result.username); | ||
}); | ||
|
||
after(async () => { | ||
// clean restores sinon, but will throw when it tries to delete the alread-deleted orgs. | ||
// so catch that and delete the dir manually | ||
try { | ||
session?.clean(); | ||
} catch { | ||
await fs.promises.rmdir(session.dir, { recursive: true }); | ||
} | ||
}); | ||
|
||
it('should see default username in help', () => { | ||
const output = execCmd<ScratchDeleteResponse>('env delete scratch --help', { ensureExitCode: 0 }).shellOutput; | ||
expect(output).to.include(scratchUsernames[2]); | ||
}); | ||
|
||
it('should delete the 1st scratch org by alias', () => { | ||
const command = `env delete scratch --target-org ${scratchOrgAlias} --no-prompt --json`; | ||
const output = execCmd<ScratchDeleteResponse>(command, { ensureExitCode: 0 }).jsonOutput.result; | ||
expect(output.username).to.equal(scratchUsernames[0]); | ||
}); | ||
|
||
it('should delete the 2nd scratch org by username', () => { | ||
const command = `env delete scratch --target-org ${scratchUsernames[1]} --no-prompt --json`; | ||
const output = execCmd<ScratchDeleteResponse>(command, { ensureExitCode: 0 }).jsonOutput.result; | ||
expect(output.username).to.equal(scratchUsernames[1]); | ||
}); | ||
|
||
it('should delete the 3rd scratch org because it is the default', () => { | ||
const command = 'env delete scratch --no-prompt --json'; | ||
const output = execCmd<ScratchDeleteResponse>(command, { ensureExitCode: 0 }).jsonOutput.result; | ||
expect(output.username).to.equal(scratchUsernames[2]); | ||
}); | ||
}); |
Oops, something went wrong.