From 5177cc1a0a855e8a047e611a1b75f9842b3eb85e Mon Sep 17 00:00:00 2001 From: Mani <44075423+manisfdcsfdx@users.noreply.github.com> Date: Wed, 26 Feb 2020 12:13:16 +1100 Subject: [PATCH] Issue/215 (#216) Fix Issue #215 --- README.md | 2 +- .../sfpowerkit/org/scratchorg/usage.ts | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index df8a882f..e5e4e20b 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ OPTIONS --loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for this command invocation EXAMPLE - $ sfdx sfpowerkit:source:customlabel:reconcile -p path/to/customlabelfile.xml -d core + $ sfdx sfpowerkit:source:customlabel:reconcile -d path/to/customlabelfile.xml -p core Package ::: core Reconciled The Custom Labels, only to have core labels (labels with full name beginning with core_) `` diff --git a/src/commands/sfpowerkit/org/scratchorg/usage.ts b/src/commands/sfpowerkit/org/scratchorg/usage.ts index 38884050..844e1bee 100644 --- a/src/commands/sfpowerkit/org/scratchorg/usage.ts +++ b/src/commands/sfpowerkit/org/scratchorg/usage.ts @@ -46,21 +46,20 @@ export default class Usage extends SfdxCommand { this.ux.log(""); - const devhub_username = this.flags.targetdevhubusername; - // Split arguments to use spawn - const args = []; - args.push("force:data:soql:query"); - - //query - args.push("-q"); - args.push( - `SELECT count(id) In_Use, SignupEmail FROM ActiveScratchOrg group by SignupEmail` - ); - - args.push("-u"); - args.push(devhub_username); - - await spawn("sfdx", args, { stdio: "inherit" }); + if (limits.ActiveScratchOrgs.Remaining !== limits.ActiveScratchOrgs.Max) { + let scratchOrgs = await this.getScratchOrgInfo(conn); + //this.ux.log(scratchOrgs); + const output = []; + scratchOrgs.records.forEach(element => { + output.push({ + In_Use: element.In_Use, + SignupEmail: element.SignupEmail + }); + }); + this.ux.table(output, ["In_Use", "SignupEmail"]); + } else { + this.ux.log(`No Scratch org used currently.`); + } return 1; } @@ -81,4 +80,12 @@ export default class Usage extends SfdxCommand { return limits; } + private async getScratchOrgInfo(conn: core.Connection) { + let query = + "SELECT count(id) In_Use, SignupEmail FROM ActiveScratchOrg GROUP BY SignupEmail ORDER BY count(id) DESC"; + + const results = (await conn.query(query)) as any; + + return results; + } }