Mike Brocchi 9f77c868d2 feat(@angular/cli): Update command runner.
This change removes the dependency of the ember-cli command structure.
2018-03-06 17:57:38 -05:00

48 lines
1.3 KiB
TypeScript

import {CliConfig} from '../models/config';
import { Command } from '../models/command';
const SilentError = require('silent-error');
export interface GetOptions {
jsonPath: string;
global?: boolean;
}
export default class GetCommand extends Command {
public readonly name = 'get';
public readonly description = 'Get a value from the configuration. Example: ng get [key]';
public readonly arguments = ['jsonPath'];
public readonly options = [
{
name: 'global',
type: Boolean,
'default': false,
aliases: ['g'],
description: 'Get the value in the global configuration (in your home directory).'
}
];
public run(options: GetOptions) {
return new Promise<void>(resolve => {
const config = options.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(options.jsonPath);
if (value === null || value === undefined) {
throw new SilentError('Value cannot be found.');
} else if (typeof value == 'object') {
this.logger.info(JSON.stringify(value, null, 2));
} else {
this.logger.info(value.toString());
}
resolve();
});
}
}