Skip to content

Commit

Permalink
fix(@angular/cli): ng get: return whole config root when no path prov…
Browse files Browse the repository at this point in the history
…ided.

Close #5887
  • Loading branch information
prestonvanloon authored and hansl committed May 9, 2017
1 parent 382ba8d commit a5d8bc1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 1 addition & 5 deletions packages/@angular/cli/commands/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ const GetCommand = Command.extend({
+ 'you need the --global argument.');
}

if (!rawArgs[0]) {
throw new SilentError('No key specified. Run "ng help get" for usage.');
}

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

0 comments on commit a5d8bc1

Please sign in to comment.