-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathcurrent.ts
49 lines (45 loc) · 1.36 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
48
49
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { getCurrentContext, CONTEXT_FILE_PATH } from '../../../models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
ContextNotFoundError,
} from '../../../errors/context-error';
export default class ContextCurrent extends Command {
static description = 'Shows the current context that is being used';
static flags = {
help: Flags.help({ char: 'h' }),
};
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}`);
}
}
}