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

feat: list metadata/-types stdout is table #1141

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/commands/org/create/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { Duration } from '@salesforce/kit';
import { Flags } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { Interfaces } from '@oclif/core';
import requestFunctions from '../../../shared/sandboxRequest.js';
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
Expand Down Expand Up @@ -215,14 +214,12 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
private async confirmSandboxReq(sandboxReq: SandboxConfirmData): Promise<void> {
if (this.flags['no-prompt'] || this.jsonEnabled()) return;

const columns: Ux.Table.Columns<{ key: string; value: unknown }> = {
key: { header: 'Field' },
value: { header: 'Value' },
};

const data = Object.entries(sandboxReq).map(([key, value]) => ({ key, value }));
this.styledHeader('Config Sandbox Request');
this.table(data, columns, {});
this.table(data, {
key: { header: 'Field' },
value: { header: 'Value' },
});

if (
!(await this.confirm({
Expand Down
26 changes: 24 additions & 2 deletions src/commands/org/list/metadata-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fs from 'node:fs';

import { Messages } from '@salesforce/core';
import type { DescribeMetadataResult } from '@jsforce/jsforce-node/lib/api/metadata.js';
import type { DescribeMetadataObject, DescribeMetadataResult } from '@jsforce/jsforce-node/lib/api/metadata.js';
import { RegistryAccess } from '@salesforce/source-deploy-retrieve';
import { Flags, loglevel, requiredOrgFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';

Expand Down Expand Up @@ -68,7 +68,29 @@ export class ListMetadataTypes extends SfCommand<DescribeMetadataResult> {
await fs.promises.writeFile(flags['output-file'], JSON.stringify(describeResult, null, 2));
this.logSuccess(`Wrote result file to ${flags['output-file']}.`);
} else {
this.styledJSON(describeResult);
this.table(
describeResult.metadataObjects,
{
xmlName: { header: 'Xml Names' },
childXmlNames: {
header: 'Child Xml Names',
get: (row: DescribeMetadataObject) =>
row.childXmlNames.length ? `[ ${row.childXmlNames.join('\n')} ]` : '',
},
directoryName: { header: 'Directory Name' },
inFolder: { header: 'In Folder' },
metaFile: { header: 'Meta File' },
suffix: { header: 'Suffix' },
},
{
'no-truncate': true,
title: 'Metadata',
sort: 'Xml Names',
}
);
this.log(`Organizational Namespace: ${describeResult.organizationNamespace}`);
this.log(`Partial Save Allowed: ${describeResult.partialSaveAllowed}`);
this.log(`Test Required: ${describeResult.testRequired}`);
}
return describeResult;
}
Expand Down
24 changes: 23 additions & 1 deletion src/commands/org/list/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,29 @@ export class ListMetadata extends SfCommand<ListMetadataCommandResult> {
fs.writeFileSync(flags['output-file'], JSON.stringify(listResult, null, 2));
this.logSuccess(`Wrote result file to ${flags['output-file']}.`);
} else if (listResult?.length) {
this.styledJSON(listResult);
this.table(
listResult,
{
createdByName: { header: 'Created By' },
createdDate: {
header: 'Created Date',
get: (row: FileProperties) => row.createdDate.split('T')[0],
},
fullName: { header: 'Full Name' },
id: { header: 'Id' },
lastModifiedByName: { header: 'Last Modified By' },
lastModifiedDate: {
header: 'Last Modified',
get: (row: FileProperties) => row.createdDate.split('T')[0],
},
manageableState: { header: 'Manageable State' },
namespacePrefix: { header: 'Namespace Prefix' },
},
{
title: flags['metadata-type'],
sort: 'Manageable State',
}
);
} else {
this.warn(messages.getMessage('noMatchingMetadata', [flags['metadata-type'], conn.getUsername()]));
}
Expand Down
13 changes: 5 additions & 8 deletions src/commands/org/refresh/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import { Duration, omit } from '@salesforce/kit';
import { Flags } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SandboxInfo, SandboxEvents, SfError } from '@salesforce/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { Lifecycle, Messages, SandboxEvents, SandboxInfo, SfError } from '@salesforce/core';
import { Interfaces } from '@oclif/core';
import requestFunctions from '../../../shared/sandboxRequest.js';
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
Expand Down Expand Up @@ -249,14 +248,12 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
private async confirmSandboxRefresh(sandboxInfo: SandboxInfo): Promise<void> {
if (this.flags['no-prompt'] || this.jsonEnabled()) return;

const columns: Ux.Table.Columns<{ key: string; value: unknown }> = {
key: { header: 'Field' },
value: { header: 'Value' },
};

const data = Object.entries(sandboxInfo).map(([key, value]) => ({ key, value: value ?? 'null' }));
this.styledHeader('Config Sandbox Refresh');
this.table(data, columns, {});
this.table(data, {
key: { header: 'Field' },
value: { header: 'Value' },
});

if (
!(await this.confirm({
Expand Down