diff --git a/README.md b/README.md index aee8c40..af4f5ad 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` + +Tools for sandboxes (list, refresh...) + +``` +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..d2ddf1e --- /dev/null +++ b/messages/list.json @@ -0,0 +1,6 @@ +{ + "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 new file mode 100644 index 0000000..779d7b3 --- /dev/null +++ b/src/commands/texei/sandbox/list.ts @@ -0,0 +1,77 @@ +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; + + // 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])); + + } catch (error) { + + + // 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 }; + } +}