Skip to content

Commit b68e48d

Browse files
authored
fix: use new inquirer via sf-plugins-core (#917)
* fix: use new inquirer via sf-plugins-core * chore: latest plugins-core * chore: bump open lib * fix: use new option flag typing * chore: bump plugins-core * test: nonZero * test: new prompt message * docs: fix readme links * test: correct nut timeout message
1 parent 90e48c6 commit b68e48d

File tree

20 files changed

+248
-254
lines changed

20 files changed

+248
-254
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ FLAG DESCRIPTIONS
216216
sandbox.
217217
```
218218

219-
_See code: [lib/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/create/sandbox.ts)_
219+
_See code: [src/commands/org/create/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/create/sandbox.ts)_
220220

221221
## `sf org create scratch`
222222

@@ -369,7 +369,7 @@ FLAG DESCRIPTIONS
369369
Omit this flag to have Salesforce generate a unique username for your org.
370370
```
371371

372-
_See code: [lib/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/create/scratch.ts)_
372+
_See code: [src/commands/org/create/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/create/scratch.ts)_
373373

374374
## `sf org delete sandbox`
375375

@@ -413,7 +413,7 @@ EXAMPLES
413413
$ sf org delete sandbox --target-org my-sandbox --no-prompt
414414
```
415415

416-
_See code: [lib/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/delete/sandbox.ts)_
416+
_See code: [src/commands/org/delete/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/delete/sandbox.ts)_
417417

418418
## `sf org delete scratch`
419419

@@ -455,7 +455,7 @@ EXAMPLES
455455
$ sf org delete scratch --target-org my-scratch-org --no-prompt
456456
```
457457

458-
_See code: [lib/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/delete/scratch.ts)_
458+
_See code: [src/commands/org/delete/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/delete/scratch.ts)_
459459

460460
## `sf org disable tracking`
461461

@@ -493,7 +493,7 @@ EXAMPLES
493493
$ sf org disable tracking
494494
```
495495

496-
_See code: [lib/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/disable/tracking.ts)_
496+
_See code: [src/commands/org/disable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/disable/tracking.ts)_
497497

498498
## `sf org display`
499499

@@ -537,7 +537,7 @@ EXAMPLES
537537
$ sf org display --target-org TestOrg1 --verbose
538538
```
539539

540-
_See code: [lib/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/display.ts)_
540+
_See code: [src/commands/org/display.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/display.ts)_
541541

542542
## `sf org enable tracking`
543543

@@ -578,7 +578,7 @@ EXAMPLES
578578
$ sf org enable tracking
579579
```
580580

581-
_See code: [lib/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/enable/tracking.ts)_
581+
_See code: [src/commands/org/enable/tracking.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/enable/tracking.ts)_
582582

583583
## `sf org list`
584584

@@ -616,7 +616,7 @@ EXAMPLES
616616
$ sf org list --clean
617617
```
618618

619-
_See code: [lib/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/list.ts)_
619+
_See code: [src/commands/org/list.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/list.ts)_
620620

621621
## `sf org list metadata`
622622

@@ -681,7 +681,7 @@ FLAG DESCRIPTIONS
681681
Examples of metadata types that use folders are Dashboard, Document, EmailTemplate, and Report.
682682
```
683683

684-
_See code: [lib/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/list/metadata.ts)_
684+
_See code: [src/commands/org/list/metadata.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/list/metadata.ts)_
685685

686686
## `sf org list metadata-types`
687687

@@ -735,7 +735,7 @@ FLAG DESCRIPTIONS
735735
Override the api version used for api requests made by this command
736736
```
737737

738-
_See code: [lib/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/list/metadata-types.ts)_
738+
_See code: [src/commands/org/list/metadata-types.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/list/metadata-types.ts)_
739739

740740
## `sf org open`
741741

@@ -801,7 +801,7 @@ EXAMPLES
801801
$ sf org open --source-file force-app/main/default/flows/Hello.flow-meta.xml
802802
```
803803

804-
_See code: [lib/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/open.ts)_
804+
_See code: [src/commands/org/open.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/open.ts)_
805805

806806
## `sf org resume sandbox`
807807

@@ -863,7 +863,7 @@ FLAG DESCRIPTIONS
863863
returns the job ID. To resume checking the sandbox creation, rerun this command.
864864
```
865865

866-
_See code: [lib/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/resume/sandbox.ts)_
866+
_See code: [src/commands/org/resume/sandbox.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/resume/sandbox.ts)_
867867

868868
## `sf org resume scratch`
869869

@@ -909,6 +909,6 @@ FLAG DESCRIPTIONS
909909
The job ID is valid for 24 hours after you start the scratch org creation.
910910
```
911911

912-
_See code: [lib/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/lib/commands/org/resume/scratch.ts)_
912+
_See code: [src/commands/org/resume/scratch.ts](https://github.com/salesforcecli/plugin-org/blob/3.2.1/src/commands/org/resume/scratch.ts)_
913913

914914
<!-- commandsstop -->

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
8-
"@oclif/core": "^3.15.1",
8+
"@oclif/core": "^3.16.0",
99
"@salesforce/core": "^6.4.4",
1010
"@salesforce/kit": "^3.0.15",
11-
"@salesforce/sf-plugins-core": "^5.0.3",
11+
"@salesforce/sf-plugins-core": "^7.0.0",
1212
"@salesforce/source-deploy-retrieve": "^10.2.5",
13-
"chalk": "^4",
13+
"chalk": "^5.3.0",
1414
"change-case": "^5.3.0",
15-
"open": "^9.1.0"
15+
"open": "^10.0.2"
1616
},
1717
"devDependencies": {
1818
"@oclif/plugin-command-snapshot": "^5.0.5",

src/commands/force/org/create.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,6 @@ export class Create extends SfCommand<CreateResult> {
263263

264264
this.logger.debug('validation complete');
265265

266-
// If the user supplied a specific client ID, we have no way of knowing if it's
267-
// a certificate-based Connected App or not. Therefore, we have to assume that
268-
// we'll need the client secret, so prompt the user for it.
269-
const { clientSecret } = this.flags.clientid
270-
? await this.prompt<{ clientSecret: string }>([
271-
{ name: 'clientSecret', type: 'mask', message: messages.getMessage('secretPrompt') },
272-
])
273-
: { clientSecret: undefined };
274-
275266
const createCommandOptions: ScratchOrgRequest = {
276267
connectedAppConsumerKey: this.flags.clientid,
277268
durationDays: this.flags.durationdays,
@@ -282,7 +273,12 @@ export class Create extends SfCommand<CreateResult> {
282273
apiversion: this.flags['api-version'],
283274
definitionfile: this.flags.definitionfile,
284275
orgConfig: this.varArgs,
285-
clientSecret,
276+
// If the user supplied a specific client ID, we have no way of knowing if it's
277+
// a certificate-based Connected App or not. Therefore, we have to assume that
278+
// we'll need the client secret, so prompt the user for it.
279+
clientSecret: this.flags.clientid
280+
? await this.secretPrompt({ message: messages.getMessage('secretPrompt') })
281+
: undefined,
286282
setDefault: this.flags.setdefaultusername === true,
287283
alias: this.flags.setalias,
288284
tracksSource: true,

src/commands/force/org/delete.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export class Delete extends SfCommand<DeleteResult> {
6161
// we either need permission to proceed without a prompt OR get the user to confirm
6262
if (
6363
flags['no-prompt'] ||
64-
(await this.confirm(messages.getMessage('confirmDelete', [isSandbox ? 'sandbox' : 'scratch', resolvedUsername])))
64+
(await this.confirm({
65+
message: messages.getMessage('confirmDelete', [isSandbox ? 'sandbox' : 'scratch', resolvedUsername]),
66+
}))
6567
) {
6668
let alreadyDeleted = false;
6769
let successMessageKey = 'commandSandboxSuccess';

src/commands/org/create/sandbox.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
9-
108
import { Duration } from '@salesforce/kit';
119
import { Flags } from '@salesforce/sf-plugins-core';
1210
import { Lifecycle, Messages, SandboxEvents, SandboxProcessObject, SandboxRequest, SfError } from '@salesforce/core';
@@ -16,7 +14,7 @@ import requestFunctions from '../../../shared/sandboxRequest.js';
1614
import { SandboxCommandBase } from '../../../shared/sandboxCommandBase.js';
1715
import { SandboxLicenseType } from '../../../shared/orgTypes.js';
1816

19-
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
17+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2018
const messages = Messages.loadMessages('@salesforce/plugin-org', 'create.sandbox');
2119

2220
const getLicenseTypes = (): string[] => Object.values(SandboxLicenseType);
@@ -225,17 +223,11 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxProcessObje
225223
this.styledHeader('Config Sandbox Request');
226224
this.table(data, columns, {});
227225

228-
const configurationCorrect = await this.timedPrompt<{ continue: boolean }>(
229-
[
230-
{
231-
name: 'continue',
232-
type: 'confirm',
233-
message: messages.getMessage('isConfigurationOk'),
234-
},
235-
],
236-
10_000
237-
);
238-
if (!configurationCorrect.continue) {
226+
if (
227+
!(await this.confirm({
228+
message: messages.getMessage('isConfigurationOk'),
229+
}))
230+
) {
239231
throw messages.createError('error.UserNotSatisfiedWithSandboxConfig');
240232
}
241233
}

src/commands/org/create/scratch.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
166166

167167
const createCommandOptions = await buildScratchOrgRequest(
168168
flags,
169-
flags['client-id'] ? await this.clientSecretPrompt() : undefined
169+
flags['client-id'] ? await this.secretPrompt({ message: messages.getMessage('prompt.secret') }) : undefined
170170
);
171171
let lastStatus: string | undefined;
172172

@@ -210,18 +210,4 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
210210
}
211211
}
212212
}
213-
214-
private async clientSecretPrompt(): Promise<string> {
215-
const { secret } = await this.timedPrompt<{ secret: string }>(
216-
[
217-
{
218-
name: 'secret',
219-
message: messages.getMessage('prompt.secret'),
220-
type: 'password',
221-
},
222-
],
223-
secretTimeout
224-
);
225-
return secret;
226-
}
227213
}

src/commands/org/delete/sandbox.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
98
import { AuthInfo, AuthRemover, Messages, Org, SfError, StateAggregator } from '@salesforce/core';
109
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
1110
import { orgThatMightBeDeleted } from '../../../shared/flags.js';
1211

13-
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
12+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1413
const messages = Messages.loadMessages('@salesforce/plugin-org', 'delete_sandbox');
1514

1615
export interface SandboxDeleteResponse {
@@ -62,7 +61,7 @@ export default class DeleteSandbox extends SfCommand<SandboxDeleteResponse> {
6261
throw messages.createError('error.unknownSandbox', [username]);
6362
}
6463

65-
if (flags['no-prompt'] || (await this.confirm(messages.getMessage('prompt.confirm', [username])))) {
64+
if (flags['no-prompt'] || (await this.confirm({ message: messages.getMessage('prompt.confirm', [username]) }))) {
6665
try {
6766
const org = await Org.create({ aliasOrUsername: username });
6867
await org.delete();

src/commands/org/delete/scratch.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
9-
108
import { AuthInfo, AuthRemover, Messages, Org } from '@salesforce/core';
119
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
1210
import { orgThatMightBeDeleted } from '../../../shared/flags.js';
1311

14-
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
12+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1513
const messages = Messages.loadMessages('@salesforce/plugin-org', 'delete_scratch');
1614

1715
export interface ScratchDeleteResponse {
@@ -41,7 +39,10 @@ export default class DeleteScratch extends SfCommand<ScratchDeleteResponse> {
4139
const resolvedUsername = flags['target-org'];
4240
const orgId = (await AuthInfo.create({ username: resolvedUsername })).getFields().orgId as string;
4341

44-
if (flags['no-prompt'] || (await this.confirm(messages.getMessage('prompt.confirm', [resolvedUsername])))) {
42+
if (
43+
flags['no-prompt'] ||
44+
(await this.confirm({ message: messages.getMessage('prompt.confirm', [resolvedUsername]) }))
45+
) {
4546
try {
4647
const org = await Org.create({ aliasOrUsername: resolvedUsername });
4748

src/commands/org/list.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
9-
108
import { Flags, loglevel, SfCommand } from '@salesforce/sf-plugins-core';
119
import { AuthInfo, ConfigAggregator, ConfigInfo, Connection, Org, SfError, Messages, Logger } from '@salesforce/core';
1210
import { Interfaces } from '@oclif/core';
13-
import chalk from 'chalk';
11+
import chalk, { ChalkInstance } from 'chalk';
1412
import { OrgListUtil, identifyActiveOrgByStatus } from '../../shared/orgListUtil.js';
1513
import { getStyledObject } from '../../shared/orgHighlighter.js';
1614
import { ExtendedAuthFields, FullyPopulatedScratchOrgFields } from '../../shared/orgTypes.js';
1715

18-
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
16+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1917
const messages = Messages.loadMessages('@salesforce/plugin-org', 'list');
2018

2119
export const defaultOrgEmoji = '🍁';
@@ -117,7 +115,7 @@ Legend: ${defaultHubEmoji}=Default DevHub, ${defaultOrgEmoji}=Default Org ${
117115
}
118116

119117
protected async cleanScratchOrgs(scratchOrgs: ExtendedAuthFields[], prompt?: boolean): Promise<void> {
120-
if (prompt && (await this.confirm(messages.getMessage('prompt', [scratchOrgs.length]))) === false) {
118+
if (prompt && (await this.confirm({ message: messages.getMessage('prompt', [scratchOrgs.length]) })) === false) {
121119
return;
122120
}
123121

@@ -259,7 +257,7 @@ const addType =
259257
(val: ExtendedAuthFields): ExtendedAuthFieldsWithType => ({ ...val, type });
260258

261259
const colorEveryFieldButConnectedStatus =
262-
(colorFn: chalk.Chalk) =>
260+
(colorFn: ChalkInstance) =>
263261
(row: ExtendedAuthFieldsWithType): ExtendedAuthFieldsWithType =>
264262
Object.fromEntries(
265263
Object.entries(row).map(([key, val]) => [

src/commands/org/open.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*/
77

88
import path from 'node:path';
9-
10-
119
import {
1210
Flags,
1311
loglevel,
@@ -21,7 +19,7 @@ import { MetadataResolver } from '@salesforce/source-deploy-retrieve';
2119
import { apps } from 'open';
2220
import utils from '../../shared/utils.js';
2321

24-
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
22+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2523
const messages = Messages.loadMessages('@salesforce/plugin-org', 'open');
2624
const sharedMessages = Messages.loadMessages('@salesforce/plugin-org', 'messages');
2725

@@ -35,12 +33,12 @@ export class OrgOpenCommand extends SfCommand<OrgOpenOutput> {
3533
public static readonly flags = {
3634
'target-org': requiredOrgFlagWithDeprecations,
3735
'api-version': orgApiVersionFlagWithDeprecations,
38-
browser: Flags.string({
36+
browser: Flags.option({
3937
char: 'b',
4038
summary: messages.getMessage('flags.browser.summary'),
41-
options: ['chrome', 'edge', 'firefox'], // These are ones supported by "open" package
39+
options: ['chrome', 'edge', 'firefox'] as const, // These are ones supported by "open" package
4240
exclusive: ['url-only'],
43-
}),
41+
})(),
4442
path: Flags.string({
4543
char: 'p',
4644
summary: messages.getMessage('flags.path.summary'),
@@ -130,12 +128,11 @@ export class OrgOpenCommand extends SfCommand<OrgOpenOutput> {
130128
throw err;
131129
}
132130

133-
const openOptions = flags.browser
134-
? // assertion can be removed once oclif option flag typings are fixed
135-
{ app: { name: apps[flags.browser as 'chrome' | 'edge' | 'firefox'] } }
136-
: {};
137-
138-
await utils.openUrl(url, openOptions);
131+
await utils.openUrl(url, {
132+
...(flags.browser ? { app: { name: apps[flags.browser] } } : {}),
133+
// only applies on macOS. open library ignores this property as it is the default behavior on other OS
134+
newInstance: true,
135+
});
139136
return output;
140137
}
141138

0 commit comments

Comments
 (0)