forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget.ts
44 lines (33 loc) · 1.14 KB
/
get.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
import {CliConfig} from '../models/config';
const SilentError = require('silent-error');
const Command = require('../ember-cli/lib/models/command');
export interface GetOptions {
global?: boolean;
}
const GetCommand = Command.extend({
name: 'get',
description: 'Get a value from the configuration.',
works: 'everywhere',
availableOptions: [
{ name: 'global', type: Boolean, 'default': false }
],
run: function (commandOptions: GetOptions, rawArgs: string[]): Promise<void> {
return new Promise<void>(resolve => {
const config = commandOptions.global ? CliConfig.fromGlobal() : CliConfig.fromProject();
if (config === null) {
throw new SilentError('No config found. If you want to use global configuration, '
+ 'you need the --global argument.');
}
const value = config.get(rawArgs[0]);
if (value === null || value === undefined) {
throw new SilentError('Value cannot be found.');
} else if (typeof value == 'object') {
console.log(JSON.stringify(value));
} else {
console.log(value);
}
resolve();
});
}
});
export default GetCommand;