-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathlist.ts
48 lines (43 loc) · 1.17 KB
/
list.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
import { Flags } from '@oclif/core';
import Command from '../../../base';
import {
loadContextFile,
isContextFileEmpty,
CONTEXT_FILE_PATH,
} from '../../../models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
} from '../../../errors/context-error';
export default class ContextList extends Command {
static description = 'List all the stored contexts in the store';
static flags = {
help: Flags.help({ char: 'h' }),
};
async run() {
try {
const fileContent = await loadContextFile();
if (await isContextFileEmpty(fileContent)) {
this.log(`Context file "${CONTEXT_FILE_PATH}" is empty.`);
return;
}
if (fileContent) {
for (const [contextName, filePath] of Object.entries(
fileContent.store
)) {
this.log(`${contextName}: ${filePath}`);
}
}
} catch (error) {
if (
error instanceof (MissingContextFileError || ContextFileWrongFormatError)
) {
this.log(
'You have no context file configured. Run "modelina config context init" to initialize it.'
);
return;
}
throw error;
}
}
}