Skip to content

Commit c2d9e70

Browse files
prestonvanloonfilipesilva
authored andcommitted
fix(@angular/cli): ng get: return whole config root when no path provided.
Close #5887
1 parent cd6db0a commit c2d9e70

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

packages/@angular/cli/commands/get.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ const GetCommand = Command.extend({
3232
+ 'you need the --global argument.');
3333
}
3434

35-
if (!rawArgs[0]) {
36-
throw new SilentError('No key specified. Run "ng help get" for usage.');
37-
}
38-
3935
const value = config.get(rawArgs[0]);
4036

4137
if (value === null || value === undefined) {
4238
throw new SilentError('Value cannot be found.');
4339
} else if (typeof value == 'object') {
44-
console.log(JSON.stringify(value));
40+
console.log(JSON.stringify(value, null, 2));
4541
} else {
4642
console.log(value);
4743
}

packages/@angular/cli/models/config/config.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ describe('Config', () => {
3434
stringKey: 'stringValue'
3535
});
3636

37+
expect(JSON.parse(JSON.stringify(config.get()))).toEqual({
38+
requiredKey: 1,
39+
stringKeyDefault: 'defaultValue',
40+
stringKey: 'stringValue'
41+
});
3742
expect(config.get('requiredKey')).toEqual(1);
3843
expect(config.get('stringKey')).toEqual('stringValue');
3944
expect(config.get('booleanKey')).toEqual(undefined);

packages/@angular/cli/models/config/config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export class CliConfig<JsonType> {
3939
return this._config.$$alias(path, newPath);
4040
}
4141

42-
get(jsonPath: string) {
42+
get(jsonPath?: string) {
43+
if (!jsonPath) {
44+
return this._config.$$root();
45+
}
4346
return this._config.$$get(jsonPath);
4447
}
4548

tests/e2e/tests/commands/get/get.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {expectToFail} from '../../../utils/utils';
44
export default function() {
55
return Promise.resolve()
66
.then(() => expectToFail(() => ng('get', 'apps.zzz.prefix')))
7-
.then(() => expectToFail(() => ng('get')))
7+
.then(() => ng('get'))
88
.then(() => ng('get', 'apps.0.prefix'))
99
.then(({ stdout }) => {
1010
if (!stdout.match(/app/)) {

0 commit comments

Comments
 (0)