-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathearly-access-header.ts
More file actions
44 lines (42 loc) · 1.74 KB
/
early-access-header.ts
File metadata and controls
44 lines (42 loc) · 1.74 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
import { cliux, flags, configHandler, FlagInput, handleAndLogError } from '@contentstack/cli-utilities';
import { interactive } from '../../../utils';
import { Command } from '@contentstack/cli-command';
export default class RemoveEarlyAccessHeader extends Command {
static description = 'Remove Early Access header';
static aliases: string[] = ['config:remove:ea-header'];
static flags: FlagInput = {
'header-alias': flags.string({ description: '(optional) Provide the Early Access header alias name.' }),
yes: flags.boolean({
char: 'y',
description: '(optional) Force the removal of Early Access header configuration by skipping the confirmation.',
}),
};
static examples: string[] = [
'$ <%= config.bin %> <%= command.id %>',
'$ <%= config.bin %> <%= command.id %> --header-alias <value>',
];
async run() {
try {
let {
flags: { 'header-alias': earlyAccessHeaderAlias, yes: skipConfirmation },
} = await this.parse(RemoveEarlyAccessHeader);
if (!earlyAccessHeaderAlias) {
earlyAccessHeaderAlias = await interactive.askEarlyAccessHeaderAlias();
}
if (configHandler.get(`earlyAccessHeaders.${earlyAccessHeaderAlias}`) === undefined) {
cliux.error(`Early Access header not configured for alias: ${earlyAccessHeaderAlias}`);
return;
}
if (!skipConfirmation) {
const confirmation = await interactive.askConfirmation();
if (!confirmation) {
return;
}
}
configHandler.delete(`earlyAccessHeaders.${earlyAccessHeaderAlias}`);
cliux.success(`Early Access header has been successfully removed`);
} catch (error) {
handleAndLogError(error, { module: 'config-remove-early-access-header' });
}
}
}