mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 22:34:21 +08:00
parent
4f4ff9f784
commit
f3e84184ea
@ -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;
|
||||
|
||||
|
||||
@ -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'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ export interface SchematicAvailableOptions {
|
||||
description: string;
|
||||
aliases: string[];
|
||||
type: any;
|
||||
schematicType: any;
|
||||
schematicDefault: any;
|
||||
}
|
||||
|
||||
export default Task.extend({
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user