Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): ng get: return whole config root when no path provided. #5887

Closed
wants to merge 8 commits into from
4 changes: 2 additions & 2 deletions packages/@angular/cli/commands/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface GetOptions {

const GetCommand = Command.extend({
name: 'get',
description: 'Get a value from the configuration.',
description: 'Get a value from the configuration. Example: ng get [key]',
works: 'everywhere',

availableOptions: [
Expand All @@ -37,7 +37,7 @@ const GetCommand = Command.extend({
if (value === null || value === undefined) {
throw new SilentError('Value cannot be found.');
} else if (typeof value == 'object') {
console.log(JSON.stringify(value));
console.log(JSON.stringify(value, null, 2));
} else {
console.log(value);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/@angular/cli/models/config/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ describe('Config', () => {
stringKey: 'stringValue'
});

expect(JSON.parse(JSON.stringify(config.get()))).toEqual({
requiredKey: 1,
stringKeyDefault: 'defaultValue',
stringKey: 'stringValue'
});
expect(config.get('requiredKey')).toEqual(1);
expect(config.get('stringKey')).toEqual('stringValue');
expect(config.get('booleanKey')).toEqual(undefined);
Expand Down
5 changes: 4 additions & 1 deletion packages/@angular/cli/models/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export class CliConfig<JsonType> {
return this._config.$$alias(path, newPath);
}

get(jsonPath: string) {
get(jsonPath?: string) {
if (!jsonPath) {
return this._config.$$root();
}
return this._config.$$get(jsonPath);
}

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/tests/commands/get/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {expectToFail} from '../../../utils/utils';
export default function() {
return Promise.resolve()
.then(() => expectToFail(() => ng('get', 'apps.zzz.prefix')))
.then(() => ng('get'))
.then(() => ng('get', 'apps.0.prefix'))
.then(({ stdout }) => {
if (!stdout.match(/app/)) {
Expand Down