Skip to content

Commit b926161

Browse files
committed
feat: add 'source-id' and 'source-sandbox-name' flags
1 parent 77d04df commit b926161

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

command-snapshot.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@
159159
"no-auto-activate",
160160
"no-prompt",
161161
"poll-interval",
162+
"source-id",
163+
"source-sandbox-name",
162164
"target-org",
163165
"wait"
164166
],

messages/refresh.sandbox.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,33 @@ The poll interval (%d seconds) can't be larger than the wait period (%d in secon
106106
# sandboxInfoRefreshFailed
107107

108108
The sandbox org refresh failed with a result of %s.
109+
110+
# flags.source-sandbox-name.summary
111+
112+
Name of the sandbox org to clone.
113+
114+
# flags.source-sandbox-name.description
115+
116+
The value of --source-sandbox-name must be an existing sandbox. The existing sandbox, and the new sandbox specified with the --name flag, must both be associated with the production org (--target-org) that contains the sandbox licenses.
117+
118+
You can specify either --source-sandbox-name or --source-id when cloning an existing sandbox, but not both.
119+
120+
# flags.source-id.summary
121+
122+
ID of the sandbox org to clone.
123+
124+
# flags.source-id.description
125+
126+
The value of --source-id must be an existing sandbox. The existing sandbox, and the new sandbox specified with the --name flag, must both be associated with the production org (--target-org) that contains the sandbox licenses.
127+
128+
# error.bothIdFlagAndDefFilePropertyAreProvided
129+
130+
You can't specify both the --source-id and --definition-file flags, and also include the "SourceId" option in the definition file. Pick one method of cloning a sandbox and try again.
131+
132+
# error.bothNameFlagAndDefFilePropertyAreProvided
133+
134+
You can't specify both the --source-sandbox-name and --definition-file flags, and also include the "SourceSandboxName" option in the definition file. Pick one method of cloning a sandbox and try again.
135+
136+
# error.bothIdFlagAndNameDefFileAreNotAllowed
137+
138+
You can't specify both the --source-sandbox-name and --definition-file flags, and also include the "SourceId" option in the definition file. Same with the --source-id flag and "SourceSandboxName" option. Pick one method of cloning a sandbox and try again.

src/commands/org/refresh/sandbox.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Duration, omit } from '@salesforce/kit';
99
import { Flags } from '@salesforce/sf-plugins-core';
1010
import { Lifecycle, Messages, SandboxEvents, SandboxInfo, SfError } from '@salesforce/core';
1111
import { Interfaces } from '@oclif/core';
12-
import requestFunctions from '../../../shared/sandboxRequest.js';
12+
import requestFunctions, { readSandboxDefFile } from '../../../shared/sandboxRequest.js';
1313
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
1414

1515
type SandboxInfoRecord = SandboxInfo & {
@@ -69,6 +69,18 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
6969
helpValue: '<seconds>',
7070
exclusive: ['async'],
7171
}),
72+
'source-sandbox-name': Flags.string({
73+
summary: messages.getMessage('flags.source-sandbox-name.summary'),
74+
description: messages.getMessage('flags.source-sandbox-name.description'),
75+
exclusive: ['source-id'],
76+
}),
77+
'source-id': Flags.salesforceId({
78+
summary: messages.getMessage('flags.source-id.summary'),
79+
description: messages.getMessage('flags.source-id.description'),
80+
exclusive: ['source-sandbox-name'],
81+
length: 'both',
82+
char: undefined,
83+
}),
7284
async: Flags.boolean({
7385
summary: messages.getMessage('flags.async.summary'),
7486
description: messages.getMessage('flags.async.description'),
@@ -242,6 +254,16 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
242254
sandboxInfo = Object.assign(sandboxInfo, defFileContent, {
243255
SandboxName: sbxName,
244256
AutoActivate: !this.flags['no-auto-activate'],
257+
...(this.flags['source-sandbox-name']
258+
? {
259+
SourceId: await requestFunctions.getSrcIdByName(
260+
this.flags['target-org'].getConnection(),
261+
this.flags['source-sandbox-name']
262+
),
263+
}
264+
: this.flags['source-id']
265+
? { SourceId: this.flags['source-id'] }
266+
: {}),
245267
...(apexId ? { ApexClassId: apexId } : {}),
246268
...(groupId ? { ActivationUserGroupId: groupId } : {}),
247269
...(srcId ? { SourceId: srcId } : {}),
@@ -261,6 +283,22 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
261283
this.flags.wait.seconds,
262284
]);
263285
}
286+
if (!this.flags['definition-file']) {
287+
return undefined;
288+
}
289+
const parsedDef = readSandboxDefFile(this.flags['definition-file']);
290+
if (this.flags['source-id'] && parsedDef.SourceId) {
291+
throw messages.createError('error.bothIdFlagAndDefFilePropertyAreProvided');
292+
}
293+
if (this.flags['source-sandbox-name'] && parsedDef.SourceSandboxName) {
294+
throw messages.createError('error.bothNameFlagAndDefFilePropertyAreProvided');
295+
}
296+
if (this.flags['source-id'] && parsedDef.SourceSandboxName) {
297+
throw messages.createError('error.bothIdFlagAndNameDefFileAreNotAllowed');
298+
}
299+
if (this.flags['source-sandbox-name'] && parsedDef.SourceId) {
300+
throw messages.createError('error.bothIdFlagAndNameDefFileAreNotAllowed');
301+
}
264302
}
265303

266304
private initSandboxProcessData(sandboxInfo: SandboxInfo): void {

0 commit comments

Comments
 (0)