Skip to content

Commit c2a536e

Browse files
committed
feat: add --no-overwrite and --ignore flags to webapp retrieve command
1 parent c966040 commit c2a536e

File tree

6 files changed

+119
-5
lines changed

6 files changed

+119
-5
lines changed

command-snapshot.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"alias": [],
2828
"command": "webapp:retrieve",
2929
"flagAliases": [],
30-
"flagChars": ["n"],
31-
"flags": ["flags-dir", "json", "name"],
30+
"flagChars": ["i", "n"],
31+
"flags": ["flags-dir", "ignore", "json", "name", "no-overwrite"],
3232
"plugin": "@salesforce/plugin-webapp"
3333
},
3434
{

messages/webapp.retrieve.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,28 @@ This command retrieves your web app, its assets, and associated metadata from yo
1010

1111
Name of your web app to retrieve
1212

13+
# flags.no-overwrite.summary
14+
15+
Prevent overwriting existing local files
16+
17+
# flags.ignore.summary
18+
19+
File pattern to ignore during retrieval (e.g., "dist/\*\*")
20+
1321
# examples
1422

1523
- Retrieve a web app:
1624

1725
<%= config.bin %> <%= command.id %> --name myWebApp
26+
27+
- Retrieve a web app with overwrite protection:
28+
29+
<%= config.bin %> <%= command.id %> --name myWebApp --no-overwrite
30+
31+
- Retrieve a web app while ignoring specific files:
32+
33+
<%= config.bin %> <%= command.id %> --name myWebApp --ignore "dist/\*\*"
34+
35+
- Retrieve with both options:
36+
37+
<%= config.bin %> <%= command.id %> --name "myWebApp" --no-overwrite --ignore "dist/\*\*"

schemas/webapp-retrieve.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
"name": {
99
"type": "string"
1010
},
11+
"noOverwrite": {
12+
"type": "boolean"
13+
},
14+
"ignore": {
15+
"type": "string"
16+
},
1117
"success": {
1218
"type": "boolean"
1319
}
1420
},
15-
"required": ["name", "success"],
21+
"required": ["name", "noOverwrite", "success"],
1622
"additionalProperties": false
1723
}
1824
}

src/commands/webapp/retrieve.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const messages = Messages.loadMessages('@salesforce/plugin-webapp', 'webapp.retr
2222

2323
export type WebappRetrieveResult = {
2424
name: string;
25+
noOverwrite: boolean;
26+
ignore?: string;
2527
success: boolean;
2628
};
2729

@@ -36,25 +38,47 @@ export default class WebappRetrieve extends SfCommand<WebappRetrieveResult> {
3638
char: 'n',
3739
required: true,
3840
}),
41+
'no-overwrite': Flags.boolean({
42+
summary: messages.getMessage('flags.no-overwrite.summary'),
43+
default: false,
44+
}),
45+
ignore: Flags.string({
46+
summary: messages.getMessage('flags.ignore.summary'),
47+
char: 'i',
48+
required: false,
49+
}),
3950
};
4051

4152
public async run(): Promise<WebappRetrieveResult> {
4253
const { flags } = await this.parse(WebappRetrieve);
4354

4455
this.log(`Retrieving web app: ${flags.name}`);
56+
57+
if (flags['no-overwrite']) {
58+
this.log('Overwrite protection enabled - existing files will not be replaced');
59+
}
60+
61+
if (flags.ignore) {
62+
this.log(`Ignoring pattern: ${flags.ignore}`);
63+
}
64+
4565
this.log('Retrieving your web app, its assets and associated metadata from your org...');
4666

4767
// TODO: Implement web app retrieval logic
4868
// This would typically involve:
4969
// 1. Connecting to the Salesforce org
5070
// 2. Retrieving web app metadata
5171
// 3. Downloading assets and bundle
52-
// 4. Saving locally with proper structure
72+
// 4. Applying ignore patterns if specified
73+
// 5. Checking for existing files if no-overwrite is set
74+
// 6. Saving locally with proper structure
5375

5476
this.log(`Successfully retrieved ${flags.name}`);
5577

5678
return {
5779
name: flags.name,
80+
noOverwrite: flags['no-overwrite'],
81+
ignore: flags.ignore,
5882
success: true,
5983
};
6084
}

test/commands/webapp/retrieve.nut.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,31 @@ describe('webapp retrieve NUTs', () => {
2828
});
2929

3030
it('should display provided name', () => {
31-
const name = 'World';
31+
const name = 'myWebApp';
3232
const command = `webapp retrieve --name ${name}`;
3333
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
3434
expect(output).to.contain(name);
3535
});
36+
37+
it('should retrieve with no-overwrite flag', () => {
38+
const command = 'webapp retrieve --name myWebApp --no-overwrite';
39+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
40+
expect(output).to.contain('Overwrite protection enabled');
41+
expect(output).to.contain('Successfully retrieved myWebApp');
42+
});
43+
44+
it('should retrieve with ignore pattern', () => {
45+
const command = 'webapp retrieve --name myWebApp --ignore "dist/**"';
46+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
47+
expect(output).to.contain('Ignoring pattern: dist/**');
48+
expect(output).to.contain('Successfully retrieved myWebApp');
49+
});
50+
51+
it('should retrieve with both no-overwrite and ignore', () => {
52+
const command = 'webapp retrieve --name myWebApp --no-overwrite --ignore "dist/**"';
53+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
54+
expect(output).to.contain('Overwrite protection enabled');
55+
expect(output).to.contain('Ignoring pattern: dist/**');
56+
expect(output).to.contain('Successfully retrieved myWebApp');
57+
});
3658
});

test/commands/webapp/retrieve.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ describe('webapp retrieve', () => {
3333
it('retrieves webapp with required name flag', async () => {
3434
const result = await WebappRetrieve.run(['--name', 'myWebApp']);
3535
expect(result.name).to.equal('myWebApp');
36+
expect(result.noOverwrite).to.be.false;
37+
expect(result.ignore).to.be.undefined;
38+
expect(result.success).to.be.true;
39+
});
40+
41+
it('retrieves webapp with no-overwrite flag', async () => {
42+
const result = await WebappRetrieve.run(['--name', 'myWebApp', '--no-overwrite']);
43+
expect(result.name).to.equal('myWebApp');
44+
expect(result.noOverwrite).to.be.true;
45+
expect(result.success).to.be.true;
46+
});
47+
48+
it('retrieves webapp with ignore pattern', async () => {
49+
const result = await WebappRetrieve.run(['--name', 'myWebApp', '--ignore', 'dist/**']);
50+
expect(result.name).to.equal('myWebApp');
51+
expect(result.ignore).to.equal('dist/**');
52+
expect(result.success).to.be.true;
53+
});
54+
55+
it('retrieves webapp with both no-overwrite and ignore flags', async () => {
56+
const result = await WebappRetrieve.run(['--name', 'myWebApp', '--no-overwrite', '--ignore', 'dist/**']);
57+
expect(result.name).to.equal('myWebApp');
58+
expect(result.noOverwrite).to.be.true;
59+
expect(result.ignore).to.equal('dist/**');
3660
expect(result.success).to.be.true;
3761
});
3862

@@ -51,4 +75,22 @@ describe('webapp retrieve', () => {
5175
expect(output).to.include('Retrieving web app: myWebApp');
5276
expect(output).to.include('Successfully retrieved myWebApp');
5377
});
78+
79+
it('outputs overwrite protection message', async () => {
80+
await WebappRetrieve.run(['--name', 'myWebApp', '--no-overwrite']);
81+
const output = sfCommandStubs.log
82+
.getCalls()
83+
.flatMap((c) => c.args)
84+
.join('\n');
85+
expect(output).to.include('Overwrite protection enabled');
86+
});
87+
88+
it('outputs ignore pattern message', async () => {
89+
await WebappRetrieve.run(['--name', 'myWebApp', '--ignore', 'dist/**']);
90+
const output = sfCommandStubs.log
91+
.getCalls()
92+
.flatMap((c) => c.args)
93+
.join('\n');
94+
expect(output).to.include('Ignoring pattern: dist/**');
95+
});
5496
});

0 commit comments

Comments
 (0)