From 249ccf766333a792681550d3539a434a7bca18f6 Mon Sep 17 00:00:00 2001 From: Pablo Villoslada Puigcerber Date: Thu, 13 Oct 2016 16:25:17 +0200 Subject: [PATCH] fix(generate): show error when no name is specified Show custom error when user forgets the name while generating blueprints. Earlier it would fall to the dynamicPathParser function and throw a TypeError: Path must be a string. Received undefined. Close #2684 --- packages/angular-cli/commands/generate.ts | 5 +++++ tests/acceptance/generate-module.spec.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/packages/angular-cli/commands/generate.ts b/packages/angular-cli/commands/generate.ts index c3452c4d6db5..6392ce89c3f7 100644 --- a/packages/angular-cli/commands/generate.ts +++ b/packages/angular-cli/commands/generate.ts @@ -24,6 +24,11 @@ const GenerateCommand = EmberGenerateCommand.extend({ SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`); } + if (!rawArgs[1]) { + SilentError.debugOrThrow('angular-cli/commands/generate', + `The \`ng generate ${rawArgs[0]}\` command requires a name to be specified.`); + } + // Override default help to hide ember blueprints EmberGenerateCommand.prototype.printDetailedHelp = function() { const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints')); diff --git a/tests/acceptance/generate-module.spec.js b/tests/acceptance/generate-module.spec.js index aa3aeaa9b4b8..28195cf5eb53 100644 --- a/tests/acceptance/generate-module.spec.js +++ b/tests/acceptance/generate-module.spec.js @@ -30,6 +30,12 @@ describe('Acceptance: ng generate module', function () { return tmp.teardown('./tmp'); }); + it('will fail if no name is specified', function () { + return ng(['generate', 'module']).catch((error) => { + expect(error).to.equal('The `ng generate module` command requires a name to be specified.'); + }); + }); + it('ng generate module my-module', function () { return ng(['generate', 'module', 'my-module']).then(() => { expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);