forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-config.ts
More file actions
34 lines (30 loc) · 991 Bytes
/
cli-config.ts
File metadata and controls
34 lines (30 loc) · 991 Bytes
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
import { initLogger } from '@finos/calm-shared';
import { readFile } from 'fs/promises';
import { homedir } from 'os';
import { join } from 'path';
export interface CLIConfig {
calmHubUrl?: string,
calmHubPlugin?: string
}
function getUserConfigLocation(): string {
const homeDir = homedir();
return join(homeDir, '.calm.json');
}
export async function loadCliConfig(): Promise<CLIConfig | null> {
const logger = initLogger(false, 'calm-cli');
const configFilePath = getUserConfigLocation();
try {
const config = await readFile(configFilePath, 'utf8');
const parsed = JSON.parse(config) as CLIConfig;
logger.debug('Parsed user config: ' + config);
return parsed;
}
catch (err) {
if (err.code === 'ENOENT') {
logger.debug('No config file found at ' + configFilePath);
return null;
}
logger.error('Unexpected error loading user config: ', err);
return null;
}
}