mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 06:41:45 +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 Command = require('../ember-cli/lib/models/command');
|
||||||
const SilentError = require('silent-error');
|
const SilentError = require('silent-error');
|
||||||
|
|
||||||
const { cyan, yellow } = chalk;
|
const { cyan, grey, yellow } = chalk;
|
||||||
const separatorRegEx = /[\/\\]/g;
|
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 engineHost = getEngineHost();
|
||||||
const collectionName = this.getCollectionName();
|
const collectionName = this.getCollectionName();
|
||||||
const collection = getCollection(collectionName);
|
const collection = getCollection(collectionName);
|
||||||
const schematicNames: string[] = engineHost.listSchematics(collection);
|
const schematicName = rawArgs[1];
|
||||||
this.ui.writeLine(cyan('Available schematics:'));
|
if (schematicName) {
|
||||||
schematicNames.forEach(schematicName => {
|
const SchematicGetOptionsTask = require('../tasks/schematic-get-options').default;
|
||||||
this.ui.writeLine(yellow(` ${schematicName}`));
|
const getOptionsTask = new SchematicGetOptionsTask({
|
||||||
});
|
ui: this.ui,
|
||||||
this.ui.writeLine('');
|
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 (cmd === commandInput) {
|
||||||
if (commandOptions.short) {
|
if (commandOptions.short) {
|
||||||
this.ui.writeLine(command.printShortHelp(commandOptions));
|
this.ui.writeLine(command.printShortHelp(commandOptions));
|
||||||
} else if (command.printDetailedHelp(commandOptions)) {
|
} else if (command.printDetailedHelp(commandOptions, rawArgs)) {
|
||||||
this.ui.writeLine(command.printDetailedHelp(commandOptions));
|
const result = command.printDetailedHelp(commandOptions, rawArgs);
|
||||||
|
if (result instanceof Promise) {
|
||||||
|
result.then(r => this.ui.writeLine(r));
|
||||||
|
} else {
|
||||||
|
this.ui.writeLine(result);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.ui.writeLine(command.printBasicHelp(commandOptions));
|
this.ui.writeLine(command.printBasicHelp(commandOptions));
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ export interface SchematicAvailableOptions {
|
|||||||
description: string;
|
description: string;
|
||||||
aliases: string[];
|
aliases: string[];
|
||||||
type: any;
|
type: any;
|
||||||
|
schematicType: any;
|
||||||
|
schematicDefault: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Task.extend({
|
export default Task.extend({
|
||||||
@ -30,6 +32,7 @@ export default Task.extend({
|
|||||||
.map(key => ({...properties[key], ...{name: stringUtils.dasherize(key)}}))
|
.map(key => ({...properties[key], ...{name: stringUtils.dasherize(key)}}))
|
||||||
.map(opt => {
|
.map(opt => {
|
||||||
let type;
|
let type;
|
||||||
|
const schematicType = opt.type;
|
||||||
switch (opt.type) {
|
switch (opt.type) {
|
||||||
case 'string':
|
case 'string':
|
||||||
type = String;
|
type = String;
|
||||||
@ -54,11 +57,15 @@ export default Task.extend({
|
|||||||
aliases = [...aliases, ...opt.aliases];
|
aliases = [...aliases, ...opt.aliases];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const schematicDefault = opt.default;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...opt,
|
...opt,
|
||||||
aliases,
|
aliases,
|
||||||
type,
|
type,
|
||||||
default: undefined // do not carry over schematics defaults
|
schematicType,
|
||||||
|
default: undefined, // do not carry over schematics defaults
|
||||||
|
schematicDefault
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(x => x);
|
.filter(x => x);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user