Skip to content

Commit 2b81062

Browse files
committed
feat: more tables by org type
1 parent 10af940 commit 2b81062

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

messages/list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Use one of the "org login" commands or "org create scratch" to add or create a s
5858

5959
# noResultsFound
6060

61-
No non-scratch orgs found.
61+
No %s found.
6262

6363
# cleanWarning
6464

src/commands/org/list.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ Messages.importMessagesDirectory(__dirname);
1616
const messages = Messages.loadMessages('@salesforce/plugin-org', 'list');
1717

1818
export type OrgListResult = {
19+
/**
20+
* @deprecated
21+
* preserved for backward json compatibility. Duplicates devHubs, sandboxes, regularOrgs, which should be preferred*/
1922
nonScratchOrgs: ExtendedAuthFields[];
2023
scratchOrgs: FullyPopulatedScratchOrgFields[];
24+
sandboxes: ExtendedAuthFields[];
25+
regularOrgs: ExtendedAuthFields[];
26+
devHubs: ExtendedAuthFields[];
2127
};
28+
2229
export class OrgListCommand extends SfCommand<OrgListResult> {
2330
public static readonly summary = messages.getMessage('summary');
2431
public static readonly examples = messages.getMessages('examples');
@@ -56,6 +63,9 @@ export class OrgListCommand extends SfCommand<OrgListResult> {
5663
this.flags = flags;
5764
const metaConfigs = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, flags);
5865
const groupedSortedOrgs = {
66+
devHubs: metaConfigs.devHubs.map(decorateWithDefaultStatus).sort(comparator),
67+
regularOrgs: metaConfigs.regularOrgs.map(decorateWithDefaultStatus).sort(comparator),
68+
sandboxes: metaConfigs.sandboxes.map(decorateWithDefaultStatus).sort(comparator),
5969
nonScratchOrgs: metaConfigs.nonScratchOrgs.map(decorateWithDefaultStatus).sort(comparator),
6070
scratchOrgs: metaConfigs.scratchOrgs.map(decorateWithDefaultStatus).sort(comparator),
6171
expiredScratchOrgs: metaConfigs.scratchOrgs.filter((org) => !identifyActiveOrgByStatus(org)),
@@ -70,13 +80,19 @@ export class OrgListCommand extends SfCommand<OrgListResult> {
7080
}
7181

7282
const result = {
83+
regularOrgs: groupedSortedOrgs.regularOrgs,
84+
sandboxes: groupedSortedOrgs.sandboxes,
7385
nonScratchOrgs: groupedSortedOrgs.nonScratchOrgs,
86+
devHubs: groupedSortedOrgs.devHubs,
7487
scratchOrgs: flags.all
7588
? groupedSortedOrgs.scratchOrgs
7689
: groupedSortedOrgs.scratchOrgs.filter(identifyActiveOrgByStatus),
7790
};
7891

79-
this.printOrgTable(result.nonScratchOrgs, flags['skip-connection-status']);
92+
// this.printOrgTable(result.nonScratchOrgs, flags['skip-connection-status']);
93+
this.printOrgTable(result.devHubs, flags['skip-connection-status'], 'DevHubs');
94+
this.printOrgTable(result.regularOrgs, flags['skip-connection-status'], 'Orgs');
95+
this.printOrgTable(result.sandboxes, flags['skip-connection-status'], 'Sandboxes');
8096

8197
this.printScratchOrgTable(result.scratchOrgs);
8298

@@ -112,10 +128,11 @@ export class OrgListCommand extends SfCommand<OrgListResult> {
112128
);
113129
}
114130

115-
protected printOrgTable(nonScratchOrgs: ExtendedAuthFields[], skipconnectionstatus: boolean): void {
131+
protected printOrgTable(nonScratchOrgs: ExtendedAuthFields[], skipconnectionstatus: boolean, title: string): void {
116132
if (!nonScratchOrgs.length) {
117-
this.log(messages.getMessage('noResultsFound'));
133+
this.info(messages.getMessage('noResultsFound', [title]));
118134
} else {
135+
this.info(title);
119136
const rows = nonScratchOrgs
120137
.map((row) => getStyledObject(row))
121138
.map((org) =>
@@ -126,32 +143,28 @@ export class OrgListCommand extends SfCommand<OrgListResult> {
126143
)
127144
);
128145

129-
this.table(
130-
rows,
131-
{
132-
defaultMarker: {
133-
header: '',
134-
get: (data): string => data.defaultMarker ?? '',
135-
},
136-
alias: {
137-
header: 'ALIAS',
138-
get: (data): string => data.alias ?? '',
139-
},
140-
username: { header: 'USERNAME' },
141-
orgId: { header: 'ORG ID' },
142-
...(!skipconnectionstatus ? { connectedStatus: { header: 'CONNECTED STATUS' } } : {}),
146+
this.table(rows, {
147+
defaultMarker: {
148+
header: '',
149+
get: (data): string => data.defaultMarker ?? '',
143150
},
144-
{
145-
title: 'Non-scratch orgs',
146-
}
147-
);
151+
alias: {
152+
header: 'ALIAS',
153+
get: (data): string => data.alias ?? '',
154+
},
155+
username: { header: 'USERNAME' },
156+
orgId: { header: 'ORG ID' },
157+
...(!skipconnectionstatus ? { connectedStatus: { header: 'CONNECTED STATUS' } } : {}),
158+
});
148159
}
160+
this.log();
149161
}
150162

151163
private printScratchOrgTable(scratchOrgs: FullyPopulatedScratchOrgFields[]): void {
152164
if (scratchOrgs.length === 0) {
153-
this.log(messages.getMessage('noActiveScratchOrgs'));
165+
this.info(messages.getMessage('noActiveScratchOrgs'));
154166
} else {
167+
this.info(this.flags.all ? 'Scratch Orgs' : 'Active Scratch Orgs (use --all to see all)');
155168
// One or more rows are available.
156169
// we only need a few of the props for our table. Oclif table doesn't like extra props non-string props.
157170
const rows = scratchOrgs
@@ -195,12 +208,13 @@ export class OrgListCommand extends SfCommand<OrgListResult> {
195208
}
196209
: {}),
197210
expirationDate: { header: 'EXPIRATION DATE' },
198-
},
199-
{
200-
title: 'Scratch orgs',
201211
}
212+
// {
213+
// title: 'Scratch orgs',
214+
// }
202215
);
203216
}
217+
this.log();
204218
}
205219
}
206220

src/shared/orgListUtil.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type OrgGroups = {
3838
type OrgGroupsFullyPopulated = {
3939
nonScratchOrgs: ExtendedAuthFields[];
4040
scratchOrgs: FullyPopulatedScratchOrgFields[];
41+
regularOrgs: ExtendedAuthFields[];
42+
sandboxes: ExtendedAuthFields[];
43+
devHubs: ExtendedAuthFields[];
4144
};
4245

4346
type ExtendedScratchOrgInfo = Record &
@@ -93,6 +96,9 @@ export class OrgListUtil {
9396
return {
9497
nonScratchOrgs,
9598
scratchOrgs,
99+
sandboxes: nonScratchOrgs.filter(sandboxFilter),
100+
regularOrgs: nonScratchOrgs.filter(regularOrgFilter),
101+
devHubs: nonScratchOrgs.filter(devHubFilter),
96102
};
97103
}
98104

@@ -367,3 +373,7 @@ const removeRestrictedInfoFromConfig = (
367373
config: AuthFieldsFromFS,
368374
properties: string[] = ['refreshToken', 'clientSecret']
369375
): AuthFieldsFromFS => omit<Omit<AuthFieldsFromFS, 'refreshToken' | 'clientSecret'>>(config, properties);
376+
377+
const sandboxFilter = (org: AuthFieldsFromFS): boolean => Boolean(org.isSandbox);
378+
const regularOrgFilter = (org: AuthFieldsFromFS): boolean => !org.isSandbox && !org.isDevHub;
379+
const devHubFilter = (org: AuthFieldsFromFS): boolean => Boolean(org.isDevHub);

0 commit comments

Comments
 (0)