generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from salesforcecli/bm/W-10657353
feat: new command org:status
- Loading branch information
Showing
11 changed files
with
433 additions
and
125 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,43 +1,86 @@ | ||
[ | ||
{ | ||
"command": "force:org:beta:create", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"apiversion", | ||
"clientid", | ||
"definitionfile", | ||
"durationdays", | ||
"json", | ||
"loglevel", | ||
"noancestors", | ||
"nonamespace", | ||
"retry", | ||
"setalias", | ||
"setdefaultusername", | ||
"targetdevhubusername", | ||
"targetusername", | ||
"type", | ||
"wait" | ||
] | ||
}, | ||
{ | ||
"command": "force:org:delete", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": ["apiversion", "json", "loglevel", "noprompt", "targetdevhubusername", "targetusername"] | ||
}, | ||
{ | ||
"command": "force:org:display", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": ["apiversion", "json", "loglevel", "targetusername", "verbose"] | ||
}, | ||
{ | ||
"command": "force:org:list", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": ["all", "clean", "json", "loglevel", "noprompt", "skipconnectionstatus", "verbose"] | ||
}, | ||
{ | ||
"command": "force:org:open", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": ["apiversion", "browser", "json", "loglevel", "path", "targetusername", "urlonly"] | ||
} | ||
] | ||
{ | ||
"command": "force:org:beta:create", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"apiversion", | ||
"clientid", | ||
"definitionfile", | ||
"durationdays", | ||
"json", | ||
"loglevel", | ||
"noancestors", | ||
"nonamespace", | ||
"retry", | ||
"setalias", | ||
"setdefaultusername", | ||
"targetdevhubusername", | ||
"targetusername", | ||
"type", | ||
"wait" | ||
] | ||
}, | ||
{ | ||
"command": "force:org:delete", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"apiversion", | ||
"json", | ||
"loglevel", | ||
"noprompt", | ||
"targetdevhubusername", | ||
"targetusername" | ||
] | ||
}, | ||
{ | ||
"command": "force:org:display", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"apiversion", | ||
"json", | ||
"loglevel", | ||
"targetusername", | ||
"verbose" | ||
] | ||
}, | ||
{ | ||
"command": "force:org:list", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"all", | ||
"clean", | ||
"json", | ||
"loglevel", | ||
"noprompt", | ||
"skipconnectionstatus", | ||
"verbose" | ||
] | ||
}, | ||
{ | ||
"command": "force:org:open", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"apiversion", | ||
"browser", | ||
"json", | ||
"loglevel", | ||
"path", | ||
"targetusername", | ||
"urlonly" | ||
] | ||
}, | ||
{ | ||
"command": "force:org:status", | ||
"plugin": "@salesforce/plugin-org", | ||
"flags": [ | ||
"apiversion", | ||
"json", | ||
"loglevel", | ||
"sandboxname", | ||
"setalias", | ||
"setdefaultusername", | ||
"targetusername", | ||
"wait" | ||
] | ||
} | ||
] |
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,13 @@ | ||
{ | ||
"examples": [ | ||
"sfdx force:org:status --sandboxname DevSbx1 --setalias MySandbox -u prodOrg", | ||
"sfdx force:org:status --sandboxname DevSbx1 --wait 45 --setdefaultusername -u prodOrg" | ||
], | ||
"description": "report status of sandbox creation or clone and authenticate to it\nUse this command to check the status of your sandbox creation or clone and, if the sandbox is ready, authenticate to it.\nUse the --wait (-w) parameter to specify the number of minutes that the command waits for the sandbox creation or clone to complete before returning control of the terminal to you.\nSet the --targetusername (-u) parameter to the username or alias of the production org that contains the sandbox license.", | ||
"flags": { | ||
"sandboxname": "name of the sandbox org to check status for", | ||
"wait": "number of minutes to wait while polling for status", | ||
"setdefaultusername": "set the created or cloned org as your default", | ||
"setalias": "alias for the created or cloned org" | ||
} | ||
} |
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,98 @@ | ||
/* | ||
* 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 { EOL } from 'os'; | ||
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; | ||
import { | ||
Config, | ||
Lifecycle, | ||
Messages, | ||
Aliases, | ||
SandboxEvents, | ||
StatusEvent, | ||
ResultEvent, | ||
SandboxProcessObject, | ||
} from '@salesforce/core'; | ||
import { Duration } from '@salesforce/kit'; | ||
import { SandboxReporter } from '../../../shared/sandboxReporter'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-org', 'status'); | ||
|
||
export class OrgStatusCommand extends SfdxCommand { | ||
public static readonly examples = messages.getMessage('examples').split(EOL); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly requiresProject = false; | ||
public static readonly requiresUsername = true; | ||
|
||
public static readonly flagsConfig: FlagsConfig = { | ||
sandboxname: flags.string({ | ||
char: 'n', | ||
description: messages.getMessage('flags.sandboxname'), | ||
required: true, | ||
}), | ||
setdefaultusername: flags.boolean({ | ||
char: 's', | ||
description: messages.getMessage('flags.setdefaultusername'), | ||
}), | ||
setalias: flags.string({ | ||
char: 'a', | ||
description: messages.getMessage('flags.setalias'), | ||
}), | ||
wait: flags.minutes({ | ||
char: 'w', | ||
description: messages.getMessage('flags.wait'), | ||
min: Duration.minutes(2), | ||
default: Duration.minutes(6), | ||
}), | ||
}; | ||
|
||
public async run(): Promise<SandboxProcessObject> { | ||
this.logger.debug('Status started with args %s ', this.flags); | ||
const lifecycle = Lifecycle.getInstance(); | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
lifecycle.on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => { | ||
this.ux.log(SandboxReporter.sandboxProgress(results)); | ||
}); | ||
|
||
lifecycle.on(SandboxEvents.EVENT_RESULT, async (results: ResultEvent) => { | ||
const resultMsg = `Sandbox ${results.sandboxProcessObj.SandboxName}(${results.sandboxProcessObj.Id}) is ready for use.`; | ||
this.ux.log(resultMsg); | ||
const { data } = SandboxReporter.logSandboxProcessResult(results); | ||
this.ux.styledHeader('Sandbox Org Status'); | ||
this.ux.table(data, { | ||
columns: [ | ||
{ key: 'key', label: 'Name' }, | ||
{ key: 'value', label: 'Value' }, | ||
], | ||
}); | ||
if (results.sandboxRes?.authUserName) { | ||
if (this.flags.setalias) { | ||
const aliases = await Aliases.create(Aliases.getDefaultOptions()); | ||
const result = await aliases.updateValue(this.flags.setalias, results.sandboxRes.authUserName); | ||
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result); | ||
} | ||
if (this.flags.setdefaultusername) { | ||
const globalConfig: Config = this.configAggregator.getGlobalConfig(); | ||
globalConfig.set(Config.DEFAULT_USERNAME, results.sandboxRes.authUserName); | ||
const result = await globalConfig.write(); | ||
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result); | ||
} | ||
} | ||
}); | ||
|
||
this.logger.debug('Calling auth for SandboxName args: %s ', this.flags.sandboxname); | ||
const results = await this.org.sandboxStatus(this.flags.sandboxname, { wait: this.flags.wait as Duration }); | ||
this.logger.debug('Results for auth call: %s ', results); | ||
if (!results) { | ||
this.ux.styledHeader('Sandbox Org Creation Status'); | ||
this.ux.log('No SandboxProcess Result Found'); | ||
} | ||
return results; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
* 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 { $$, expect, test } from '@salesforce/command/lib/test'; | ||
import { expect, test } from '@salesforce/command/lib/test'; | ||
import { Aliases, AuthInfo, Connection, Org } from '@salesforce/core'; | ||
|
||
import * as sinon from 'sinon'; | ||
import { stubMethod, stubInterface, StubbedType } from '@salesforce/ts-sinon'; | ||
import * as utils from '../../../../src/shared/utils'; | ||
|
||
|
@@ -45,15 +45,15 @@ const fakeAuthUrl = 'fakeAuthUrl'; | |
|
||
describe('org:display', () => { | ||
let authInfoStub: StubbedType<AuthInfo>; | ||
const sandbox = sinon.createSandbox(); | ||
|
||
beforeEach(async function () { | ||
$$.SANDBOX.restore(); | ||
stubMethod($$.SANDBOX, Aliases, 'fetch') | ||
stubMethod(sandbox, Aliases, 'fetch') | ||
.withArgs('nonscratchalias') | ||
.resolves('[email protected]') | ||
.withArgs('scratchAlias') | ||
.resolves('[email protected]'); | ||
stubMethod($$.SANDBOX, utils, 'getAliasByUsername') | ||
stubMethod(sandbox, utils, 'getAliasByUsername') | ||
.withArgs('[email protected]') | ||
.resolves('nonscratchalias') | ||
.withArgs('[email protected]') | ||
|
@@ -62,9 +62,13 @@ describe('org:display', () => { | |
.resolves(undefined); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
async function prepareStubs(AuthInfoModifications: any = {}) { | ||
authInfoStub = stubInterface<AuthInfo>($$.SANDBOX, { | ||
authInfoStub = stubInterface<AuthInfo>(sandbox, { | ||
getFields: () => ({ | ||
...baseAuthInfo, | ||
...AuthInfoModifications, | ||
|
@@ -76,7 +80,7 @@ describe('org:display', () => { | |
return 'badUrl'; | ||
}, | ||
}); | ||
stubMethod($$.SANDBOX, AuthInfo, 'create').callsFake(async () => authInfoStub); | ||
stubMethod(sandbox, AuthInfo, 'create').callsFake(async () => authInfoStub); | ||
} | ||
|
||
test | ||
|
@@ -206,16 +210,16 @@ describe('org:display', () => { | |
await prepareStubs({ | ||
devHubUsername: devHub.username, | ||
}); | ||
stubMethod($$.SANDBOX, Org, 'create').resolves(Org.prototype); | ||
stubMethod($$.SANDBOX, Org.prototype, 'getUsername').returns('[email protected]'); | ||
stubMethod(sandbox, Org, 'create').resolves(Org.prototype); | ||
stubMethod(sandbox, Org.prototype, 'getUsername').returns('[email protected]'); | ||
|
||
stubMethod($$.SANDBOX, Org.prototype, 'getOrgId').resolves(devHub.id); | ||
stubMethod($$.SANDBOX, Org.prototype, 'getDevHubOrg').resolves({ | ||
stubMethod(sandbox, Org.prototype, 'getOrgId').resolves(devHub.id); | ||
stubMethod(sandbox, Org.prototype, 'getDevHubOrg').resolves({ | ||
getUsername: () => devHub.username, | ||
}); | ||
stubMethod($$.SANDBOX, Org.prototype, 'getConnection').returns(Connection.prototype); | ||
stubMethod(sandbox, Org.prototype, 'getConnection').returns(Connection.prototype); | ||
|
||
stubMethod($$.SANDBOX, Connection.prototype, 'sobject').returns({ | ||
stubMethod(sandbox, Connection.prototype, 'sobject').returns({ | ||
find: async () => { | ||
return [ | ||
{ | ||
|
Oops, something went wrong.