-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
remove.ts
41 lines (37 loc) · 1.25 KB
/
remove.ts
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
import { Args } from '@oclif/core';
import Command from '../../../core/base';
import { removeContext, CONTEXT_FILE_PATH } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../core/errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';
export default class ContextRemove extends Command {
static description = 'Delete a context from the store';
static flags = helpFlag();
static args = {
'context-name': Args.string({description: 'Name of the context to delete', required: true}),
};
async run() {
const { args } = await this.parse(ContextRemove);
const contextName = args['context-name'];
try {
await removeContext(contextName);
this.log(`${contextName} successfully deleted`);
} catch (e) {
if (
e instanceof (MissingContextFileError || ContextFileWrongFormatError)
) {
this.log(
'You have no context file configured. Run "asyncapi config context init" to initialize it.'
);
return;
} else if (e instanceof ContextFileEmptyError) {
this.log(`Context file "${CONTEXT_FILE_PATH}" is empty.`);
return;
}
throw e;
}
}
}