From 14e411492b52fe48900194e95639a163c0922c55 Mon Sep 17 00:00:00 2001 From: Fabien Huot Date: Sun, 25 Nov 2018 20:04:04 +0100 Subject: [PATCH 1/2] new taxei command : sandbox list --- README.md | 27 ++++++++++- messages/list.json | 6 +++ src/commands/texei/sandbox/list.ts | 76 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 messages/list.json create mode 100644 src/commands/texei/sandbox/list.ts diff --git a/README.md b/README.md index aee8c40..4aaf978 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Link the plugin: sfdx plugins:link . * [`sfdx texei:package:dependencies:install`](#sfdx-texeipackagedependenciesinstall) +* [`sfdx texei:sandbox:list`](#sfdx-texeisandboxlist) * [`sfdx texei:user:update`](#sfdx-texeiuserupdate) ## `sfdx texei:package:dependencies:install` @@ -58,7 +59,29 @@ EXAMPLE $ texei:package:dependencies:install -u MyScratchOrg -v MyDevHub -k "1:MyPackage1Key 2: 3:MyPackage3Key" -b "DEV" ``` -_See code: [src/commands/texei/package/dependencies/install.ts](https://github.com/texei/texei-sfdx-plugin/blob/v0.0.3/src/commands/texei/package/dependencies/install.ts)_ +_See code: [src/commands/texei/package/dependencies/install.ts](https://github.com/texei/texei-sfdx-plugin/blob/v0.0.4/src/commands/texei/package/dependencies/install.ts)_ + +## `sfdx texei:sandbox:list` + +Updates the current user of a scratch org + +``` +USAGE + $ sfdx texei:sandbox:list + +OPTIONS + -l, --list=list the = pairs you’re updating + -u, --targetusername=targetusername username or alias for the target org; overrides default target org + -v, --targetdevhubusername=targetdevhubusername username or alias for the dev hub org; overrides default dev hub org + --apiversion=apiversion override the api version used for api requests made by this command + --json format output as json + --loglevel=(trace|debug|info|warn|error|fatal) logging level for this command invocation + +EXAMPLE + $ sfdx texei:sandbox:list --targetusername myOrg@example.com +``` + +_See code: [src/commands/texei/sandbox/list.ts](https://github.com/texei/texei-sfdx-plugin/blob/v0.0.4/src/commands/texei/sandbox/list.ts)_ ## `sfdx texei:user:update` @@ -81,5 +104,5 @@ EXAMPLES $ sfdx texei:user:update --values "UserPermissionsKnowledgeUser=true --json" ``` -_See code: [src/commands/texei/user/update.ts](https://github.com/texei/texei-sfdx-plugin/blob/v0.0.3/src/commands/texei/user/update.ts)_ +_See code: [src/commands/texei/user/update.ts](https://github.com/texei/texei-sfdx-plugin/blob/v0.0.4/src/commands/texei/user/update.ts)_ diff --git a/messages/list.json b/messages/list.json new file mode 100644 index 0000000..6d359c4 --- /dev/null +++ b/messages/list.json @@ -0,0 +1,6 @@ +{ + "commandDescription": "Updates the current user of a scratch org", + "valuesFlagDescription": "the = pairs you’re updating", + "errorNoOrgResults": "No results found for the organization '%s'.", + "list":"valuesFlagDescription" +} diff --git a/src/commands/texei/sandbox/list.ts b/src/commands/texei/sandbox/list.ts new file mode 100644 index 0000000..6e66fa1 --- /dev/null +++ b/src/commands/texei/sandbox/list.ts @@ -0,0 +1,76 @@ +import { core, SfdxCommand, flags } from '@salesforce/command'; +var exec = require('child-process-promise').exec; + +// Initialize Messages with the current plugin directory +core.Messages.importMessagesDirectory(__dirname); + +// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, +// or any library that is using the messages framework can also be loaded this way. +const messages = core.Messages.loadMessages('texei-sfdx-plugin', 'list'); + +export default class List extends SfdxCommand { + + public static description = messages.getMessage('commandDescription'); + + public static examples = [ + `$ sfdx texei:sandbox:list --targetusername myOrg@example.com`, + ]; + + //public static args = [{ name: 'file' }]; + + protected static flagsConfig = { + // TODO: add flag for time color to warn refresh + list: flags.string({ char: 'l', description: messages.getMessage('valuesFlagDescription') }) + }; + + // Comment this out if your command does not require an org username + protected static requiresUsername = true; + + // Comment this out if your command does not support a hub org username + protected static supportsDevhubUsername = true; + + // Set this to true if your command requires a project workspace; 'requiresProject' is false by default + protected static requiresProject = false; + + public async run(): Promise { + + const values = this.flags.values; + + // this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername + //const userName = this.org.getUsername(); + + // TODO: update to use jsforce ? + // https://jsforce.github.io/document/#update + //const updateUserCommand = `sfdx force:data:record:update -s User -w "UserName=${userName}" -v "${values}"`; + + let result = []; + const conn = this.hubOrg.getConnection(); + + try { + + var sandboxList = {}; +conn.query("SELECT Id, DisplayName, MemberEntity, Instance, IsSandbox, OrgStatus, OrgEdition FROM EnvironmentHubMember WHERE OrgStatus != 'Deleted'ORDER BY DisplayName", function(err, result) { + if (err) { return console.error(err); } + for (var i = 0; i < result.totalSize; i++) { + console.log('id:' + result.records[i].Id, ' name: 'result.records[i].DisplayName, ' isSandbox: 'result.records[i].IsSandbox); + } +}); + + + + + + this.ux.table(sandboxList); + } catch (error) { + + result = error.stderr; + + + // Throw an error, sfdx library will manage the way to display it + //throw new core.SfdxError(records); + } + + // Everything went fine, return an object that will be used for --json + return { org: this.org.getOrgId(), message: result }; + } +} From 66d4a79f2e7e6186616dee9b97e5e8f500783dbd Mon Sep 17 00:00:00 2001 From: Fabien Huot Date: Fri, 7 Dec 2018 16:38:06 +0100 Subject: [PATCH 2/2] Sandbox:list command ready to use --- README.md | 2 +- messages/list.json | 2 +- messages/update.json | 2 +- src/commands/texei/sandbox/list.ts | 51 +++++++++++++++--------------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4aaf978..af4f5ad 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ _See code: [src/commands/texei/package/dependencies/install.ts](https://github.c ## `sfdx texei:sandbox:list` -Updates the current user of a scratch org +Tools for sandboxes (list, refresh...) ``` USAGE diff --git a/messages/list.json b/messages/list.json index 6d359c4..d2ddf1e 100644 --- a/messages/list.json +++ b/messages/list.json @@ -1,5 +1,5 @@ { - "commandDescription": "Updates the current user of a scratch org", + "commandDescription": "Tools for sandboxes (list, refresh...) ", "valuesFlagDescription": "the = pairs you’re updating", "errorNoOrgResults": "No results found for the organization '%s'.", "list":"valuesFlagDescription" diff --git a/messages/update.json b/messages/update.json index 586345d..0211279 100644 --- a/messages/update.json +++ b/messages/update.json @@ -1,5 +1,5 @@ { - "commandDescription": "Updates the current user of a scratch org", + "commandDescription": "Updates the current user of a scratch org!!", "valuesFlagDescription": "the = pairs you’re updating", "errorNoOrgResults": "No results found for the organization '%s'." } diff --git a/src/commands/texei/sandbox/list.ts b/src/commands/texei/sandbox/list.ts index 6e66fa1..779d7b3 100644 --- a/src/commands/texei/sandbox/list.ts +++ b/src/commands/texei/sandbox/list.ts @@ -36,34 +36,35 @@ export default class List extends SfdxCommand { const values = this.flags.values; - // this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername - //const userName = this.org.getUsername(); - - // TODO: update to use jsforce ? - // https://jsforce.github.io/document/#update - //const updateUserCommand = `sfdx force:data:record:update -s User -w "UserName=${userName}" -v "${values}"`; - - let result = []; - const conn = this.hubOrg.getConnection(); - - try { - - var sandboxList = {}; -conn.query("SELECT Id, DisplayName, MemberEntity, Instance, IsSandbox, OrgStatus, OrgEdition FROM EnvironmentHubMember WHERE OrgStatus != 'Deleted'ORDER BY DisplayName", function(err, result) { - if (err) { return console.error(err); } - for (var i = 0; i < result.totalSize; i++) { - console.log('id:' + result.records[i].Id, ' name: 'result.records[i].DisplayName, ' isSandbox: 'result.records[i].IsSandbox); - } -}); - - + // Define the query for retrieving Sandboxes informations + const query = "SELECT Id, SandboxName, Description, LicenseType FROM SandboxInfo"; + const conn = this.org.getConnection(); + + try { + //Define our ouput list + let output = []; + + // Query the org + const result = await conn.tooling.query(query) as any; + + // + for (const record of result.records) { + // TODO: Add description and cut if too long ? + const sandboxInfo = { + id: record.Id, + name: record.SandboxName, + type: record.LicenseType + //description: record.Description + } + // Push result in ouput list + output.push(sandboxInfo); + } + // Show the list + this.ux.table(output, Object.keys(output[0])); - this.ux.table(sandboxList); - } catch (error) { - - result = error.stderr; + } catch (error) { // Throw an error, sfdx library will manage the way to display it