-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
current.ts
47 lines (43 loc) · 1.37 KB
/
current.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
42
43
44
45
46
47
import Command from '../../../core/base';
import { getCurrentContext, CONTEXT_FILE_PATH } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
ContextNotFoundError,
} from '../../../core/errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';
export default class ContextCurrent extends Command {
static description = 'Shows the current context that is being used';
static flags = helpFlag();
async run() {
let fileContent;
try {
fileContent = await getCurrentContext();
} 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;
} else if (
e instanceof ContextNotFoundError ||
(fileContent && !fileContent.current)
) {
this.log(
'No context is set as current. Run "asyncapi config context" to see all available options.'
);
return;
}
throw e;
}
if (fileContent) {
this.log(`${fileContent.current}: ${fileContent.context}`);
}
}
}