Skip to content

Commit db39ccf

Browse files
Broccohansl
authored andcommitted
refactor: Refactor help output
1 parent 453ff5c commit db39ccf

File tree

2 files changed

+69
-30
lines changed

2 files changed

+69
-30
lines changed

packages/@angular/cli/commands/generate.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -192,42 +192,20 @@ export default Command.extend({
192192
const collection = getCollection(collectionName);
193193
const schematicName = rawArgs[1];
194194
if (schematicName) {
195-
const SchematicGetOptionsTask = require('../tasks/schematic-get-options').default;
196-
const getOptionsTask = new SchematicGetOptionsTask({
195+
const SchematicGetHelpOutputTask = require('../tasks/schematic-get-help-output').default;
196+
const getHelpOutputTask = new SchematicGetHelpOutputTask({
197197
ui: this.ui,
198198
project: this.project
199199
});
200-
return getOptionsTask.run({
200+
return getHelpOutputTask.run({
201201
schematicName,
202202
collectionName
203203
})
204-
.then((availableOptions: SchematicAvailableOptions[]) => {
205-
const output: string[] = [];
206-
output.push(cyan(`ng generate ${schematicName} ${cyan('[name]')} ${cyan('<options...>')}`));
207-
availableOptions
208-
.filter(opt => opt.name !== 'name')
209-
.forEach(opt => {
210-
let text = cyan(` --${opt.name}`);
211-
if (opt.schematicType) {
212-
text += cyan(` (${opt.schematicType})`);
213-
}
214-
if (opt.schematicDefault) {
215-
text += cyan(` (Default: ${opt.schematicDefault})`);
216-
}
217-
if (opt.description) {
218-
text += ` ${opt.description}`;
219-
}
220-
output.push(text);
221-
if (opt.aliases && opt.aliases.length > 0) {
222-
const aliasText = opt.aliases.reduce(
223-
(acc, curr) => {
224-
return acc + ` -${curr}`;
225-
},
226-
'');
227-
output.push(grey(` aliases: ${aliasText}`));
228-
}
229-
});
230-
return output.join('\n');
204+
.then((output: string[]) => {
205+
return [
206+
cyan(`ng generate ${schematicName} ${cyan('[name]')} ${cyan('<options...>')}`),
207+
...output
208+
].join('\n');
231209
});
232210
} else {
233211
const schematicNames: string[] = engineHost.listSchematics(collection);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import chalk from 'chalk';
2+
const Task = require('../ember-cli/lib/models/task');
3+
4+
const { cyan, grey } = chalk;
5+
6+
export interface SchematicGetHelpOptions {
7+
collectionName: string;
8+
schematicName: string;
9+
}
10+
11+
export interface SchematicAvailableOptions {
12+
name: string;
13+
description: string;
14+
aliases: string[];
15+
type: any;
16+
schematicType: any;
17+
schematicDefault: any;
18+
}
19+
20+
export default Task.extend({
21+
run: function ({schematicName, collectionName}: SchematicGetHelpOptions):
22+
Promise<SchematicAvailableOptions[]> {
23+
24+
const SchematicGetOptionsTask = require('./schematic-get-options').default;
25+
const getOptionsTask = new SchematicGetOptionsTask({
26+
ui: this.ui,
27+
project: this.project
28+
});
29+
return getOptionsTask.run({
30+
schematicName: schematicName,
31+
collectionName: collectionName,
32+
})
33+
.then((availableOptions: SchematicAvailableOptions[]) => {
34+
const output: string[] = [];
35+
availableOptions
36+
.filter(opt => opt.name !== 'name')
37+
.forEach(opt => {
38+
let text = cyan(` --${opt.name}`);
39+
if (opt.schematicType) {
40+
text += cyan(` (${opt.schematicType})`);
41+
}
42+
if (opt.schematicDefault) {
43+
text += cyan(` (Default: ${opt.schematicDefault})`);
44+
}
45+
if (opt.description) {
46+
text += ` ${opt.description}`;
47+
}
48+
output.push(text);
49+
if (opt.aliases && opt.aliases.length > 0) {
50+
const aliasText = opt.aliases.reduce(
51+
(acc, curr) => {
52+
return acc + ` -${curr}`;
53+
},
54+
'');
55+
output.push(grey(` aliases: ${aliasText}`));
56+
}
57+
});
58+
return output;
59+
});
60+
}
61+
});

0 commit comments

Comments
 (0)