-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.ts
More file actions
80 lines (67 loc) · 2.31 KB
/
delete.ts
File metadata and controls
80 lines (67 loc) · 2.31 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
/*
* 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 {Args} from '@oclif/core';
import {MrtCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {deleteEnvVar} from '@salesforce/b2c-tooling-sdk/operations/mrt';
import {t, withDocs} from '../../../../i18n/index.js';
/**
* Delete an environment variable from an MRT project environment.
*/
export default class MrtEnvVarDelete extends MrtCommand<typeof MrtEnvVarDelete> {
static args = {
key: Args.string({
description: 'Environment variable name',
required: true,
}),
};
static description = withDocs(
t('commands.mrt.env.var.delete.description', 'Delete an environment variable from a Managed Runtime environment'),
'/cli/mrt.html#b2c-mrt-env-var-delete',
);
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> MY_VAR --project acme-storefront --environment production',
'<%= config.bin %> <%= command.id %> OLD_API_KEY -p my-project -e staging',
];
static flags = {
...MrtCommand.baseFlags,
};
protected operations = {
deleteEnvVar,
};
async run(): Promise<{key: string; project: string; environment: string}> {
// Prevent deletion in safe mode
this.assertDestructiveOperationAllowed('delete environment variable');
this.requireMrtCredentials();
const {key} = this.args;
const {mrtProject: project, mrtEnvironment: environment} = this.resolvedConfig.values;
if (!project) {
this.error('MRT project is required. Provide --project flag, set MRT_PROJECT, or set mrtProject in dw.json.');
}
if (!environment) {
this.error(
'MRT environment is required. Provide --environment flag, set MRT_ENVIRONMENT, or set mrtEnvironment in dw.json.',
);
}
await this.operations.deleteEnvVar(
{
projectSlug: project,
environment,
key,
origin: this.resolvedConfig.values.mrtOrigin,
},
this.getMrtAuth(),
);
this.log(
t('commands.mrt.env.var.delete.success', 'Deleted {{key}} from {{project}}/{{environment}}', {
key,
project,
environment,
}),
);
return {key, project, environment};
}
}