Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wr/tables #823

Merged
merged 13 commits into from
Oct 30, 2024
2 changes: 1 addition & 1 deletion messages/package_version_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ Successfully deleted the package version with ID: %s

# humanSuccessUndelete

Successfully undeleted the package version.
Successfully undeleted package version %s.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4",
"@salesforce/core": "^8.6.1",
"@salesforce/core": "^8.6.2",
"@salesforce/kit": "^3.2.3",
"@salesforce/packaging": "^4.2.9",
"@salesforce/sf-plugins-core": "^11.3.12",
"@salesforce/packaging": "^4.2.15",
"@salesforce/sf-plugins-core": "^12.0.11",
"chalk": "^5.3.0"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/package/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class PackageCreateCommand extends SfCommand<PackageCreate> {
}

private display(result: PackageCreate): void {
this.styledHeader('Ids');
this.table([{ name: 'Package Id', value: result.Id }], { name: { header: 'NAME' }, value: { header: 'VALUE' } });
this.table({ data: [{ name: 'Package Id', value: result.Id }], title: 'Ids' });
}
}
29 changes: 13 additions & 16 deletions src/commands/package/installed/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ export class PackageInstalledListCommand extends SfCommand<PackageInstalledComma
await SubscriberPackageVersion.installedList(flags['target-org'].getConnection(flags['api-version']))
).map(transformRow);

this.table(
records,
columns,

{ 'no-truncate': true }
);
this.table({
data: records,
columns: [
{ key: 'Id', name: 'ID' },
{ key: 'SubscriberPackageId', name: 'Package ID' },
{ key: 'SubscriberPackageName', name: 'Package Name' },
{ key: 'SubscriberPackageNamespace', name: 'Namespace' },
{ key: 'SubscriberPackageVersionId', name: 'Package Version ID' },
{ key: 'SubscriberPackageVersionName', name: 'Version Name' },
{ key: 'SubscriberPackageVersionNumber', name: 'Version' },
],
overflow: 'wrap',
});

return records;
}
Expand All @@ -75,13 +82,3 @@ const transformRow = (r: InstalledPackages): PackageInstalledListResult => ({
}
: {}),
});

const columns = {
Id: { header: 'ID' },
SubscriberPackageId: { header: 'Package ID' },
SubscriberPackageName: { header: 'Package Name' },
SubscriberPackageNamespace: { header: 'Namespace' },
SubscriberPackageVersionId: { header: 'Package Version ID' },
SubscriberPackageVersionName: { header: 'Version Name' },
SubscriberPackageVersionNumber: { header: 'Version' },
};
36 changes: 15 additions & 21 deletions src/commands/package/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,25 @@ export class PackageListCommand extends SfCommand<PackageListCommandResult> {
}

private displayResults(results: Package2Result[], verbose = false, apiVersion: string): void {
this.styledHeader(chalk.blue(`Packages [${results.length}]`));
const columns = {
NamespacePrefix: { header: messages.getMessage('namespace') },
Name: { header: messages.getMessage('name') },
Id: { header: messages.getMessage('id') },
Alias: { header: messages.getMessage('alias') },
Description: { header: messages.getMessage('description') },
ContainerOptions: {
header: messages.getMessage('package-type'),
},
const data = results.map((r) => ({
'Namespace Prefix': r.NamespacePrefix,
Name: r.Name,
Id: r.Id,
Alias: r.Alias,
Description: r.Description,
ContainerOptions: r.ContainerOptions,
...(verbose
? {
SubscriberPackageId: { header: messages.getMessage('package-id') },
ConvertedFromPackageId: { header: messages.getMessage('convertedFromPackageId') },
IsOrgDependent: { header: messages.getMessage('isOrgDependent') },
PackageErrorUsername: { header: messages.getMessage('error-notification-username') },
CreatedBy: { header: messages.getMessage('createdBy') },
'Package Id': r.SubscriberPackageId,
'Converted From Package Id': r.ConvertedFromPackageId,
'Org-Dependent Unlocked Package': r.IsOrgDependent,
'Error Notification Username': r.PackageErrorUsername,
'Created By': r.CreatedBy,
...(parseInt(apiVersion, 10) >= 59 ? { 'App Analytics Enabled': r.AppAnalyticsEnabled } : {}),
}
: {}),
...(verbose && parseInt(apiVersion, 10) >= 59
? { AppAnalyticsEnabled: { header: messages.getMessage('app-analytics-enabled') } }
: {}),
};

this.table(results, columns);
}));
this.table({ data, title: chalk.blue(`Packages [${results.length}]`) });
}
}

Expand Down
68 changes: 16 additions & 52 deletions src/commands/package/version/create/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ export type CreateListCommandResult = Array<
}
>;

type ColumnDataHeader = {
header?: string;
};
type ColumnData = {
Id: ColumnDataHeader;
Status: ColumnDataHeader;
Package2Id: ColumnDataHeader;
Package2VersionId: ColumnDataHeader;
SubscriberPackageVersionId: ColumnDataHeader;
Tag: ColumnDataHeader;
Branch: ColumnDataHeader;
CreatedDate: ColumnDataHeader;
CreatedBy: ColumnDataHeader;
VersionName?: ColumnDataHeader;
VersionNumber?: ColumnDataHeader;
ConvertedFromVersionId?: ColumnDataHeader;
};

type Status = 'Queued' | 'InProgress' | 'Success' | 'Error';

export class PackageVersionCreateListCommand extends SfCommand<CreateListCommandResult> {
Expand Down Expand Up @@ -86,48 +68,30 @@ export class PackageVersionCreateListCommand extends SfCommand<CreateListCommand
if (results.length === 0) {
this.warn('No results found');
} else {
this.styledHeader(chalk.blue(`Package Version Create Requests [${results.length}]`));
const columnData: ColumnData = {
Id: {},
Status: {
header: messages.getMessage('status'),
},
Package2Id: {
header: messages.getMessage('package-id'),
},
Package2VersionId: {
header: messages.getMessage('packageVersionId'),
},
SubscriberPackageVersionId: {
header: messages.getMessage('subscriberPackageVersionId'),
},
Tag: {
header: messages.getMessage('tag'),
},
Branch: {
header: messages.getMessage('branch'),
},
CreatedDate: { header: 'Created Date' },
CreatedBy: {
header: messages.getMessage('createdBy'),
},
};

if (flags['show-conversions-only']) {
columnData.ConvertedFromVersionId = { header: messages.getMessage('convertedFromVersionId') };
}

if (flags.verbose) {
try {
results = await this.fetchVerboseData(results);
columnData.VersionName = { header: 'Version Name' };
columnData.VersionNumber = { header: 'Version Number' };
} catch (err) {
const errMsg = typeof err === 'string' ? err : err instanceof Error ? err.message : 'unknown error';
this.warn(`error when retrieving verbose data (package name and version) due to: ${errMsg}`);
}
}
this.table(results, columnData, { 'no-truncate': true });

const data = results.map((r) => ({
Id: r.Id,
Status: r.Status,
'Package Id': r.Package2Id,
'Package Version Id': r.Package2VersionId,
'Subscriber Package Version Id': r.SubscriberPackageVersionId,
Tag: r.Tag,
Branch: r.Branch,
'Created Date': r.CreatedDate,
'Created By': r.CreatedBy,
...(flags['show-conversions-only'] ? { 'Converted From Version Id': r.ConvertedFromVersionId } : {}),
...(flags.verbose ? { 'Version Name': r.VersionName, 'Version Number': r.VersionNumber } : {}),
}));

this.table({ data, overflow: 'wrap', title: chalk.blue(`Package Version Create Requests [${results.length}]`) });
}

return results;
Expand Down
28 changes: 12 additions & 16 deletions src/commands/package/version/create/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,56 +61,52 @@ export class PackageVersionCreateReportCommand extends SfCommand<ReportCommandRe

const data = [
{
key: pvclMessages.getMessage('id'),
name: pvclMessages.getMessage('id'),
value: record.Id,
},
{
key: pvclMessages.getMessage('status'),
name: pvclMessages.getMessage('status'),
value: camelCaseToTitleCase(record.Status),
},
{
key: pvclMessages.getMessage('package-id'),
name: pvclMessages.getMessage('package-id'),
value: record.Package2Id,
},
{
key: pvclMessages.getMessage('packageVersionId'),
name: pvclMessages.getMessage('packageVersionId'),
value: record.Package2VersionId,
},
{
key: pvclMessages.getMessage('subscriberPackageVersionId'),
name: pvclMessages.getMessage('subscriberPackageVersionId'),
value: record.SubscriberPackageVersionId,
},
{
key: pvclMessages.getMessage('tag'),
name: pvclMessages.getMessage('tag'),
value: record.Tag,
},
{
key: pvclMessages.getMessage('branch'),
name: pvclMessages.getMessage('branch'),
value: record.Branch,
},
{ key: 'Created Date', value: record.CreatedDate },
{ name: 'Created Date', value: record.CreatedDate },
{
key: pvclMessages.getMessage('installUrl'),
name: pvclMessages.getMessage('installUrl'),
value: installUrlValue,
},
{
key: plMessages.getMessage('createdBy'),
name: plMessages.getMessage('createdBy'),
value: record.CreatedBy,
},
];

if (record.ConvertedFromVersionId) {
data.push({
key: pvlMessages.getMessage('convertedFromVersionId'),
name: pvlMessages.getMessage('convertedFromVersionId'),
value: record.ConvertedFromVersionId,
});
}

this.styledHeader(chalk.blue('Package Version Create Request'));
this.table(data, {
key: { header: 'Name' },
value: { header: 'Value' },
});
this.table({ data, title: chalk.blue('Package Version Create Request') });

if (record.Error?.length > 0) {
this.log('');
Expand Down
Loading