Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SchematicAvailableOptions } from '../tasks/schematic-get-options';
const Command = require('../ember-cli/lib/models/command');
const SilentError = require('silent-error');

const { cyan, yellow } = chalk;
const { cyan, grey, yellow } = chalk;
const separatorRegEx = /[\/\\]/g;


Expand Down Expand Up @@ -186,15 +186,57 @@ export default Command.extend({
});
},

printDetailedHelp: function () {
printDetailedHelp: function (_options: any, rawArgs: any): string | Promise<string> {
const engineHost = getEngineHost();
const collectionName = this.getCollectionName();
const collection = getCollection(collectionName);
const schematicNames: string[] = engineHost.listSchematics(collection);
this.ui.writeLine(cyan('Available schematics:'));
schematicNames.forEach(schematicName => {
this.ui.writeLine(yellow(` ${schematicName}`));
});
this.ui.writeLine('');
const schematicName = rawArgs[1];
if (schematicName) {
const SchematicGetOptionsTask = require('../tasks/schematic-get-options').default;
const getOptionsTask = new SchematicGetOptionsTask({
ui: this.ui,
project: this.project
});
return getOptionsTask.run({
schematicName,
collectionName
})
.then((availableOptions: SchematicAvailableOptions[]) => {
const output: string[] = [];
output.push(cyan(`ng generate ${schematicName} ${cyan('[name]')} ${cyan('<options...>')}`));
availableOptions
.filter(opt => opt.name !== 'name')
.forEach(opt => {
let text = cyan(` --${opt.name}`);
if (opt.schematicType) {
text += cyan(` (${opt.schematicType})`);
}
if (opt.schematicDefault) {
text += cyan(` (Default: ${opt.schematicDefault})`);
}
if (opt.description) {
text += ` ${opt.description}`;
}
output.push(text);
if (opt.aliases && opt.aliases.length > 0) {
const aliasText = opt.aliases.reduce(
(acc, curr) => {
return acc + ` -${curr}`;
},
'');
output.push(grey(` aliases: ${aliasText}`));
}
});
return output.join('\n');
});
} else {
const schematicNames: string[] = engineHost.listSchematics(collection);
const output: string[] = [];
output.push(cyan('Available schematics:'));
schematicNames.forEach(schematicName => {
output.push(yellow(` ${schematicName}`));
});
return Promise.resolve(output.join('\n'));
}
}
});
9 changes: 7 additions & 2 deletions packages/@angular/cli/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ const HelpCommand = Command.extend({
if (cmd === commandInput) {
if (commandOptions.short) {
this.ui.writeLine(command.printShortHelp(commandOptions));
} else if (command.printDetailedHelp(commandOptions)) {
this.ui.writeLine(command.printDetailedHelp(commandOptions));
} else if (command.printDetailedHelp(commandOptions, rawArgs)) {
const result = command.printDetailedHelp(commandOptions, rawArgs);
if (result instanceof Promise) {
result.then(r => this.ui.writeLine(r));
} else {
this.ui.writeLine(result);
}
} else {
this.ui.writeLine(command.printBasicHelp(commandOptions));
}
Expand Down
9 changes: 8 additions & 1 deletion packages/@angular/cli/tasks/schematic-get-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface SchematicAvailableOptions {
description: string;
aliases: string[];
type: any;
schematicType: any;
schematicDefault: any;
}

export default Task.extend({
Expand All @@ -30,6 +32,7 @@ export default Task.extend({
.map(key => ({...properties[key], ...{name: stringUtils.dasherize(key)}}))
.map(opt => {
let type;
const schematicType = opt.type;
switch (opt.type) {
case 'string':
type = String;
Expand All @@ -54,11 +57,15 @@ export default Task.extend({
aliases = [...aliases, ...opt.aliases];
}

const schematicDefault = opt.default;

return {
...opt,
aliases,
type,
default: undefined // do not carry over schematics defaults
schematicType,
default: undefined, // do not carry over schematics defaults
schematicDefault
};
})
.filter(x => x);
Expand Down