From ccfc9f58077ef53dbbfc973c5d63d6950be28268 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 11 Apr 2023 11:43:10 -0500 Subject: [PATCH] feat: more scratch org creation flags --- command-snapshot.json | 4 ++++ messages/create_scratch.md | 22 ++++++++++++++++++++++ src/commands/org/create/scratch.ts | 26 +++++++++++++++++++++++--- test/nut/scratchCreate.nut.ts | 13 ++++++++++++- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/command-snapshot.json b/command-snapshot.json index f99dd485..f284ef35 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -78,14 +78,18 @@ "async", "client-id", "definition-file", + "description", "duration-days", "edition", "json", + "name", "no-ancestors", "no-namespace", + "release", "set-default", "target-dev-hub", "track-source", + "username", "wait" ], "alias": ["env:create:scratch"] diff --git a/messages/create_scratch.md b/messages/create_scratch.md index 9c1bd2b0..de278d98 100644 --- a/messages/create_scratch.md +++ b/messages/create_scratch.md @@ -96,6 +96,28 @@ Create the scratch org with no namespace, even if the Dev Hub has a namespace. Number of days before the org expires. +# flags.username.summary + +Set the username of the scratch org admin user. Overrides any value from the definition file. + +# flags.username.description + +The username must be unique within the entire scratch org and sandbox universe. You need to add logic to ensure uniqueness. + +Omit this flag to have Salesforce generate a unique username for your org. + +# flags.description.summary + +Set the description of the scratch org in the Dev Hub. Overrides any value from the definition file. + +# flags.name.summary + +Set the orgName property of the scratch org in the Dev Hub. Overrides any value from the definition file. + +# flags.release.summary + +By default, orgs will on the same release as the Dev Hub. During the preview period you can override this behavior to opt in or out of the new release. + # prompt.secret OAuth client secret of your personal connected app diff --git a/src/commands/org/create/scratch.ts b/src/commands/org/create/scratch.ts index 4a4b4d3a..a584fed5 100644 --- a/src/commands/org/create/scratch.ts +++ b/src/commands/org/create/scratch.ts @@ -115,6 +115,20 @@ export default class EnvCreateScratch extends SfCommand { description: messages.getMessage('flags.track-source.description'), allowNo: true, }), + username: Flags.string({ + summary: messages.getMessage('flags.username.summary'), + description: messages.getMessage('flags.username.description'), + }), + description: Flags.string({ + summary: messages.getMessage('flags.description.summary'), + }), + name: Flags.string({ + summary: messages.getMessage('flags.name.summary'), + }), + release: Flags.string({ + summary: messages.getMessage('flags.release.summary'), + options: ['preview', 'previous'], + }), }; public async run(): Promise { const lifecycle = Lifecycle.getInstance(); @@ -123,9 +137,15 @@ export default class EnvCreateScratch extends SfCommand { if (!baseUrl) { throw new SfError('No instance URL found for the dev hub'); } - const orgConfig = flags['definition-file'] - ? (JSON.parse(await fs.promises.readFile(flags['definition-file'], 'utf-8')) as Record) - : { edition: flags.edition }; + const orgConfig = { + ...(flags['definition-file'] + ? (JSON.parse(await fs.promises.readFile(flags['definition-file'], 'utf-8')) as Record) + : { edition: flags.edition }), + ...(flags.username ? { username: flags.username } : {}), + ...(flags.description ? { description: flags.description } : {}), + ...(flags.name ? { orgName: flags.name } : {}), + ...(flags.release ? { release: flags.release } : {}), + }; const createCommandOptions: ScratchOrgCreateOptions = { hubOrg: flags['target-dev-hub'], diff --git a/test/nut/scratchCreate.nut.ts b/test/nut/scratchCreate.nut.ts index 615f5981..194885f0 100644 --- a/test/nut/scratchCreate.nut.ts +++ b/test/nut/scratchCreate.nut.ts @@ -6,7 +6,7 @@ */ import * as fs from 'fs'; import * as path from 'path'; -import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { execCmd, genUniqueString, TestSession } from '@salesforce/cli-plugins-testkit'; import { assert, expect } from 'chai'; import { AuthFields, Messages, Global, StateAggregator } from '@salesforce/core'; import { secretTimeout } from '../../src/commands/org/create/scratch'; @@ -85,6 +85,17 @@ describe('env create scratch NUTs', () => { ).jsonOutput?.result; expect(resp).to.have.all.keys(keys); }); + it('creates an org from config file with "override" flags ', () => { + const expectedUsername = genUniqueString('%s@nut.org'); + const resp = execCmd( + `env:create:scratch -f config/project-scratch-def.json --json --username ${expectedUsername} --description "new one" --name TheOrg --wait 60`, + { + ensureExitCode: 0, + } + ).jsonOutput?.result; + expect(resp).to.have.all.keys(keys); + expect(resp?.username).to.equal(expectedUsername); + }); it('creates an org with tracking disabled ', async () => { const resp = execCmd( 'env:create:scratch --edition developer --no-track-source --json --wait 60',