Skip to content

Commit

Permalink
feat: more scratch org creation flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 11, 2023
1 parent 82afd32 commit ccfc9f5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
4 changes: 4 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
22 changes: 22 additions & 0 deletions messages/create_scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions src/commands/org/create/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
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<ScratchCreateResponse> {
const lifecycle = Lifecycle.getInstance();
Expand All @@ -123,9 +137,15 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
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<string, unknown>)
: { edition: flags.edition };
const orgConfig = {
...(flags['definition-file']
? (JSON.parse(await fs.promises.readFile(flags['definition-file'], 'utf-8')) as Record<string, unknown>)
: { 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'],
Expand Down
13 changes: 12 additions & 1 deletion test/nut/scratchCreate.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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('%[email protected]');
const resp = execCmd<ScratchCreateResponse>(
`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<ScratchCreateResponse>(
'env:create:scratch --edition developer --no-track-source --json --wait 60',
Expand Down

0 comments on commit ccfc9f5

Please sign in to comment.