Skip to content

Commit 03adf2a

Browse files
authored
Merge pull request #1358 from salesforcecli/sl/W-16857079
feat: W-16857079 - add a --snapshot flag for creating scratch org
2 parents 7e0a471 + 0302fbc commit 03adf2a

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

command-snapshot.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"alias": ["env:create:scratch"],
2828
"command": "org:create:scratch",
2929
"flagAliases": [],
30-
"flagChars": ["a", "c", "d", "e", "f", "i", "m", "t", "v", "w", "y"],
30+
"flagChars": ["a", "c", "d", "e", "f", "i", "m", "s", "t", "v", "w", "y"],
3131
"flags": [
3232
"admin-email",
3333
"alias",
@@ -45,6 +45,7 @@
4545
"no-namespace",
4646
"release",
4747
"set-default",
48+
"snapshot",
4849
"source-org",
4950
"target-dev-hub",
5051
"track-source",

messages/create_scratch.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ Create a scratch org.
44

55
# description
66

7-
There are two ways to create a scratch org: either specify a definition file that contains the options or use the --edition flag to specify the one required option.
7+
There are four ways to create a scratch org:
88

9-
For either method, you can also use these flags; if you use them with --definition-file, they override their equivalent option in the scratch org definition file:
9+
* Specify a definition file that contains the scratch org options.
10+
* Use the --edition flag to specify the one required option; this method doesn't require a defintion file.
11+
* Use the --snapshot flag to create a scratch org from a snapshot. Snapshots are a point-in-time copy of a scratch org; you create a snapshot with the "sf org create snapshot" command.
12+
* Use the --source-org flag to create a scratch org from an org shape. Org shapes mimic the baseline setup of a source org without the extraneous data and metadata; you create an org shape with the "sf org create shape" command.
13+
14+
The --edition, --snapshot, and --source-org flags are mutually exclusive, which means if you specify one, you can't also specify the others.
15+
16+
For any of the methods, you can also use these flags; if you use them with --definition-file, they override their equivalent option in the scratch org definition file:
1017

1118
* --description
1219
* --name (equivalent to the "orgName" option)
1320
* --username
1421
* --release
15-
* --edition
1622
* --admin-email (equivalent to the "adminEmail" option)
17-
* --source-org (equivalent to the "sourceOrg" option)
1823

19-
If you want to set options other than the preceding ones, such as org features or settings, you must use a definition file.
24+
If you want to set options such as org features or settings, you must use a definition file.
2025

2126
You must specify a Dev Hub to create a scratch org, either with the --target-dev-hub flag or by setting your default Dev Hub with the target-dev-hub configuration variable.
2227

@@ -34,6 +39,10 @@ You must specify a Dev Hub to create a scratch org, either with the --target-dev
3439

3540
<%= config.bin %> <%= command.id %> --edition enterprise --alias my-scratch-org --target-dev-hub MyHub --release preview
3641

42+
- Create a scratch org from a snapshot called "NightlyBranch"; be sure you specify the same Dev Hub org associated with the snapshot. We recommend you increase the --wait time because creating a scratch org from a snapshot can take a while:
43+
44+
<%= config.bin %> <%= command.id %> --alias my-scratch-org --target-dev-hub MyHub --snapshot NightlyBranch --wait 10
45+
3746
# flags.target-dev-hub.summary
3847

3948
Username or alias of the Dev Hub org.
@@ -62,6 +71,14 @@ Don't include second-generation managed package (2GP) ancestors in the scratch o
6271

6372
Salesforce edition of the scratch org. Overrides the value of the "edition" option in the definition file, if set.
6473

74+
# flags.snapshot.summary
75+
76+
Name of the snapshot to use when creating this scratch org. Overrides the value of the "snapshot" option in the defintion file, if set.
77+
78+
# flags.snapshot.description
79+
80+
To view the names of the available snapshots for a given Dev Hub org, run the "sf org list snapshot" command.
81+
6582
# flags.async.summary
6683

6784
Request the org, but don't wait for it to complete.
@@ -92,7 +109,11 @@ Email address that will be applied to the org's admin user. Overrides the value
92109

93110
# flags.source-org.summary
94111

95-
15-character ID of the org whose shape the new scratch org will be based on. Overrides the value of the "sourceOrg" option in the definition file, if set.
112+
15-character ID of the org shape that the new scratch org is based on. Overrides the value of the "sourceOrg" option in the definition file, if set.
113+
114+
# flags.source-org.description
115+
116+
To view the names of the available org shapes for a given Dev Hub org, run the "sf org list shape" command.
96117

97118
# flags.wait.summary
98119

src/commands/org/create/scratch.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
8080
'partner-group',
8181
'partner-professional',
8282
],
83+
exclusive: ['snapshot', 'source-org'],
8384
// eslint-disable-next-line @typescript-eslint/require-await
8485
parse: async (value: string) => {
8586
// the API expects partner editions in `partner <EDITION>` format.
@@ -91,6 +92,13 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
9192
},
9293
helpGroup: definitionFileHelpGroupName,
9394
}),
95+
snapshot: Flags.string({
96+
char: 's',
97+
summary: messages.getMessage('flags.snapshot.summary'),
98+
description: messages.getMessage('flags.snapshot.description'),
99+
exclusive: ['edition', 'source-org'],
100+
helpGroup: definitionFileHelpGroupName,
101+
}),
94102
'no-namespace': Flags.boolean({
95103
char: 'm',
96104
summary: messages.getMessage('flags.no-namespace.summary'),
@@ -151,6 +159,8 @@ export default class OrgCreateScratch extends SfCommand<ScratchCreateResponse> {
151159
}),
152160
'source-org': Flags.salesforceId({
153161
summary: messages.getMessage('flags.source-org.summary'),
162+
description: messages.getMessage('flags.source-org.description'),
163+
exclusive: ['edition', 'snapshot'],
154164
startsWith: '00D',
155165
length: 15,
156166
helpGroup: definitionFileHelpGroupName,

src/shared/scratchOrgRequest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import { Interfaces } from '@oclif/core';
1010
import { ScratchOrgCreateOptions } from '@salesforce/core';
1111
import { Duration } from '@salesforce/kit';
1212
import EnvCreateScratch from '../commands/org/create/scratch.js';
13+
1314
/**
1415
* Provide the parsed flags
1516
* Returns the objet necessary to create a scratch org
1617
*/
18+
1719
export const buildScratchOrgRequest = async (
1820
flags: Interfaces.InferredFlags<typeof EnvCreateScratch.flags>,
1921
clientSecret?: string
@@ -23,6 +25,7 @@ export const buildScratchOrgRequest = async (
2325
? (JSON.parse(await fs.promises.readFile(flags['definition-file'], 'utf-8')) as Record<string, unknown>)
2426
: {}),
2527
...(flags.edition ? { edition: flags.edition } : {}),
28+
...(flags.snapshot ? { snapshot: flags.snapshot } : {}),
2629
...(flags.username ? { username: flags.username } : {}),
2730
...(flags.description ? { description: flags.description } : {}),
2831
...(flags.name ? { orgName: flags.name } : {}),

test/shared/scratchOrgRequest.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ describe('buildScratchOrgRequest function', () => {
4141
expect(result.orgConfig).to.deep.equal({ edition: 'developer' });
4242
});
4343

44+
it('snapshot as only flag', async () => {
45+
const flags = await paramsToFlags(['--snapshot', 'my-snapshot-name']);
46+
const result = await buildScratchOrgRequest(flags);
47+
expect(result.durationDays).to.equal(7);
48+
expect(result.orgConfig).to.deep.equal({ snapshot: 'my-snapshot-name' });
49+
});
50+
4451
describe('source-org', () => {
4552
it('valid source-org as only flag', async () => {
4653
const flags = await paramsToFlags(['--source-org', '00D123456789012']);

0 commit comments

Comments
 (0)