Skip to content

Commit 4376fd4

Browse files
committed
fix: parse comma or newline-separated cmp names
1 parent 888a3c6 commit 4376fd4

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@oclif/errors": "1.3.4",
1717
"@salesforce/command": "3.0.5",
1818
"@salesforce/core": "2.15.2",
19+
"get-stdin": "8.0.0",
1920
"lodash": "4.17.20",
2021
"picomatch": "2.2.2",
2122
"tslib": "2.0.3"

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function getMetadataComponentsFromStdinOrString(
88
): Promise<Array<MetadataComponent>> {
99
let rawComponentNames = [];
1010
if (commaSeparatedMetadataComponentNames === '-') {
11-
rawComponentNames = await getStdin().split('\n');
11+
rawComponentNames = (await getStdin()).split('\n');
1212
} else {
1313
rawComponentNames = commaSeparatedMetadataComponentNames.split(',');
1414
}

src/commands/package.xml/create.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export default class PackageXmlCreateCommand extends SfdxCommand {
2828
protected static flagsConfig = {
2929
metadata: flags.string({
3030
char: 'm',
31-
description: 'comma-separated list of metadata component names'
31+
description: 'comma-separated list of metadata component names',
32+
required: true
3233
}),
3334
resultfile: flags.filepath({
3435
char: 'f',

test/cli.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect } from 'chai';
2+
import { getMetadataComponentsFromStdinOrString } from '../src/cli';
3+
4+
describe('cli', () => {
5+
describe('getMetadataComponentsFromStdinOrString()', () => {
6+
it('parses comma-separated metadata component names from a string', async () => {
7+
expect(
8+
await getMetadataComponentsFromStdinOrString(
9+
'CustomObject:Account,ApexPage:Foo'
10+
)
11+
).to.deep.equal([
12+
{ type: 'CustomObject', fullName: 'Account' },
13+
{ type: 'ApexPage', fullName: 'Foo' }
14+
]);
15+
});
16+
it.skip('parses new-line delimited metadata component names from STDIN', async () => {
17+
process.stdin.isTTY = false;
18+
const promise = getMetadataComponentsFromStdinOrString('-');
19+
process.stdin.push('CustomObject:Account');
20+
process.stdin.push('ApexPage:Foo');
21+
process.stdin.emit('end');
22+
await new Promise((resolve) => setTimeout(resolve, 1000));
23+
expect(await promise).to.deep.equal([
24+
{ type: 'CustomObject', fullName: 'Account' },
25+
{ type: 'ApexPage', fullName: 'Foo' }
26+
]);
27+
});
28+
});
29+
});

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,6 +3259,11 @@ get-package-type@^0.1.0:
32593259
resolved "https://registry.yarnpkg.com/get-package-type/-/get-package-type-0.1.0.tgz#8de2d803cff44df3bc6c456e6668b36c3926e11a"
32603260
integrity sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==
32613261

3262+
3263+
version "8.0.0"
3264+
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-8.0.0.tgz#cbad6a73feb75f6eeb22ba9e01f89aa28aa97a53"
3265+
integrity sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==
3266+
32623267
get-stdin@^4.0.1:
32633268
version "4.0.1"
32643269
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"

0 commit comments

Comments
 (0)