From 309118a9c6ba655d12350ca9b4db2ddb14a8d391 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sat, 8 Apr 2017 07:52:13 -0600 Subject: [PATCH 1/5] fix(@angular/cli): Throw error when no key provided for ng get --- packages/@angular/cli/commands/get.ts | 6 +++++- tests/e2e/tests/commands/get/get.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/@angular/cli/commands/get.ts b/packages/@angular/cli/commands/get.ts index ee0bca96ab35..0568e179ba76 100644 --- a/packages/@angular/cli/commands/get.ts +++ b/packages/@angular/cli/commands/get.ts @@ -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 project.name', works: 'everywhere', availableOptions: [ @@ -32,6 +32,10 @@ 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) { diff --git a/tests/e2e/tests/commands/get/get.ts b/tests/e2e/tests/commands/get/get.ts index b66fb2e9ceb1..0922256309a4 100644 --- a/tests/e2e/tests/commands/get/get.ts +++ b/tests/e2e/tests/commands/get/get.ts @@ -4,6 +4,7 @@ import {expectToFail} from '../../../utils/utils'; export default function() { return Promise.resolve() .then(() => expectToFail(() => ng('get', 'apps.zzz.prefix'))) + .then(() => expectToFail(() => ng('get', undefined))) .then(() => ng('get', 'apps.0.prefix')) .then(({ stdout }) => { if (!stdout.match(/app/)) { From ef3a19c0c3a5dd44fe7e73efb66a8df095a85f9c Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sat, 8 Apr 2017 08:28:32 -0600 Subject: [PATCH 2/5] fix(@angular/cli): Throw error when no key provided for ng get --- packages/@angular/cli/commands/get.ts | 2 +- tests/e2e/tests/commands/get/get.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@angular/cli/commands/get.ts b/packages/@angular/cli/commands/get.ts index 0568e179ba76..9b8edd9aca89 100644 --- a/packages/@angular/cli/commands/get.ts +++ b/packages/@angular/cli/commands/get.ts @@ -11,7 +11,7 @@ export interface GetOptions { const GetCommand = Command.extend({ name: 'get', - description: 'Get a value from the configuration. Example: ng get project.name', + description: 'Get a value from the configuration. Example: ng get [key]', works: 'everywhere', availableOptions: [ diff --git a/tests/e2e/tests/commands/get/get.ts b/tests/e2e/tests/commands/get/get.ts index 0922256309a4..09ca1cf46984 100644 --- a/tests/e2e/tests/commands/get/get.ts +++ b/tests/e2e/tests/commands/get/get.ts @@ -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', undefined))) + .then(() => expectToFail(() => ng('get'))) .then(() => ng('get', 'apps.0.prefix')) .then(({ stdout }) => { if (!stdout.match(/app/)) { From 69c3140c7bb114b62e658e00001860f135efd159 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 9 Apr 2017 18:05:29 -0400 Subject: [PATCH 3/5] fix(@angular/cli): ng get: return whole config root when no path provided. --- packages/@angular/cli/commands/get.ts | 6 +----- packages/@angular/cli/models/config/config.spec.ts | 6 ++++-- packages/@angular/cli/models/config/config.ts | 5 ++++- tests/e2e/tests/commands/get/get.ts | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/@angular/cli/commands/get.ts b/packages/@angular/cli/commands/get.ts index 9b8edd9aca89..a0092f45f78f 100644 --- a/packages/@angular/cli/commands/get.ts +++ b/packages/@angular/cli/commands/get.ts @@ -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); } diff --git a/packages/@angular/cli/models/config/config.spec.ts b/packages/@angular/cli/models/config/config.spec.ts index 2c6c78eb8744..bd6edb50f6a7 100644 --- a/packages/@angular/cli/models/config/config.spec.ts +++ b/packages/@angular/cli/models/config/config.spec.ts @@ -29,11 +29,13 @@ describe('Config', () => { describe('Get', () => { it('works', () => { - const config = new CliConfig(null, schema, { + const rawConfigObj = { requiredKey: 1, stringKey: 'stringValue' - }); + }; + const config = new CliConfig(null, schema, rawConfigObj); + expect(config.get()).toEqual(rawConfigObj); expect(config.get('requiredKey')).toEqual(1); expect(config.get('stringKey')).toEqual('stringValue'); expect(config.get('booleanKey')).toEqual(undefined); diff --git a/packages/@angular/cli/models/config/config.ts b/packages/@angular/cli/models/config/config.ts index 7370b1ff5766..e2698ea4cfca 100644 --- a/packages/@angular/cli/models/config/config.ts +++ b/packages/@angular/cli/models/config/config.ts @@ -39,7 +39,10 @@ export class CliConfig { return this._config.$$alias(path, newPath); } - get(jsonPath: string) { + get(jsonPath?: string) { + if (!jsonPath) { + return this._config.$$root(); + } return this._config.$$get(jsonPath); } diff --git a/tests/e2e/tests/commands/get/get.ts b/tests/e2e/tests/commands/get/get.ts index 09ca1cf46984..34c70b12f197 100644 --- a/tests/e2e/tests/commands/get/get.ts +++ b/tests/e2e/tests/commands/get/get.ts @@ -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/)) { From cafe9e22200aa1eadf7cac2be54f700d8865982a Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 9 Apr 2017 18:31:57 -0400 Subject: [PATCH 4/5] fix(@angular/cli): ng get: return whole config root when no path provided. --- packages/@angular/cli/models/config/config.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@angular/cli/models/config/config.spec.ts b/packages/@angular/cli/models/config/config.spec.ts index bd6edb50f6a7..73d009aa4af8 100644 --- a/packages/@angular/cli/models/config/config.spec.ts +++ b/packages/@angular/cli/models/config/config.spec.ts @@ -35,7 +35,7 @@ describe('Config', () => { }; const config = new CliConfig(null, schema, rawConfigObj); - expect(config.get()).toEqual(rawConfigObj); + expect(JSON.parse(JSON.stringify(config.get()))).toEqual(rawConfigObj); expect(config.get('requiredKey')).toEqual(1); expect(config.get('stringKey')).toEqual('stringValue'); expect(config.get('booleanKey')).toEqual(undefined); From f903570cbcf3e583c41c4cdd40961fdd5824402e Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 9 Apr 2017 18:44:04 -0400 Subject: [PATCH 5/5] fix(@angular/cli): ng get: return whole config root when no path provided. --- packages/@angular/cli/models/config/config.spec.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/@angular/cli/models/config/config.spec.ts b/packages/@angular/cli/models/config/config.spec.ts index 73d009aa4af8..cf4a95862102 100644 --- a/packages/@angular/cli/models/config/config.spec.ts +++ b/packages/@angular/cli/models/config/config.spec.ts @@ -29,13 +29,16 @@ describe('Config', () => { describe('Get', () => { it('works', () => { - const rawConfigObj = { + const config = new CliConfig(null, schema, { requiredKey: 1, stringKey: 'stringValue' - }; - const config = new CliConfig(null, schema, rawConfigObj); + }); - expect(JSON.parse(JSON.stringify(config.get()))).toEqual(rawConfigObj); + 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);