-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdelete.ts
More file actions
97 lines (83 loc) · 2.77 KB
/
delete.ts
File metadata and controls
97 lines (83 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import * as readline from 'node:readline';
import {Args, Flags} from '@oclif/core';
import {InstanceCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {deleteCodeVersion} from '@salesforce/b2c-tooling-sdk/operations/code';
import {t, withDocs} from '../../i18n/index.js';
/**
* Simple confirmation prompt.
*/
async function confirm(message: string): Promise<boolean> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stderr,
});
return new Promise((resolve) => {
rl.question(`${message} `, (answer) => {
rl.close();
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
});
});
}
export default class CodeDelete extends InstanceCommand<typeof CodeDelete> {
static args = {
codeVersion: Args.string({
description: 'Code version ID to delete',
required: true,
}),
};
static description = withDocs(
t('commands.code.delete.description', 'Delete a code version'),
'/cli/code.html#b2c-code-delete',
);
static examples = [
'<%= config.bin %> <%= command.id %> old-version',
'<%= config.bin %> <%= command.id %> old-version --force',
'<%= config.bin %> <%= command.id %> old-version --server my-sandbox.demandware.net',
];
static flags = {
...InstanceCommand.baseFlags,
force: Flags.boolean({
char: 'f',
description: 'Skip confirmation prompt',
default: false,
}),
};
protected operations = {
confirm,
deleteCodeVersion,
};
async run(): Promise<void> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete code version');
this.requireOAuthCredentials();
const codeVersion = this.args.codeVersion;
const hostname = this.resolvedConfig.values.hostname!;
// Confirm deletion unless --force is used
if (!this.flags.force) {
const confirmed = await this.operations.confirm(
t(
'commands.code.delete.confirm',
'Are you sure you want to delete code version "{{codeVersion}}" on {{hostname}}? (y/n)',
{codeVersion, hostname},
),
);
if (!confirmed) {
this.log(t('commands.code.delete.cancelled', 'Deletion cancelled'));
return;
}
}
this.log(
t('commands.code.delete.deleting', 'Deleting code version {{codeVersion}} from {{hostname}}...', {
hostname,
codeVersion,
}),
);
await this.operations.deleteCodeVersion(this.instance, codeVersion);
this.log(t('commands.code.delete.deleted', 'Code version {{codeVersion}} deleted successfully', {codeVersion}));
}
}