Skip to content

Commit aff5257

Browse files
Broccohansl
authored andcommitted
fix(@angular/cli): Show detailed help for ng new --help
1 parent ac1b42d commit aff5257

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ const HelpCommand = Command.extend({
6767
if (commandOptions.short) {
6868
this.ui.writeLine(command.printShortHelp(commandOptions));
6969
} else if (command.printDetailedHelp(commandOptions, rawArgs)) {
70+
this.ui.writeLine('cool');
7071
const result = command.printDetailedHelp(commandOptions, rawArgs);
72+
this.ui.writeLine('not cool', result);
7173
if (result instanceof Promise) {
7274
result.then(r => this.ui.writeLine(r));
7375
} else {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import * as path from 'path';
33
import chalk from 'chalk';
44

55
import { CliConfig } from '../models/config';
6+
import { getCollection, getEngineHost } from '../utilities/schematics';
67
import { validateProjectName } from '../utilities/validate-project-name';
78
import { oneLine } from 'common-tags';
89
import { SchematicAvailableOptions } from '../tasks/schematic-get-options';
10+
import { outputFile } from 'fs-extra';
11+
12+
const { cyan, yellow } = chalk;
913

1014
const Command = require('../ember-cli/lib/models/command');
1115
const SilentError = require('silent-error');
@@ -153,6 +157,28 @@ const NewCommand = Command.extend({
153157
commandOptions.skipGit = commandOptions.skipGit === undefined ? false : commandOptions.skipGit;
154158

155159
return initTask.run(commandOptions, rawArgs);
160+
},
161+
162+
printDetailedHelp: function (): string | Promise<string> {
163+
const collectionName = this.getCollectionName();
164+
const schematicName = CliConfig.getValue('defaults.schematics.newApp');
165+
const SchematicGetHelpOutputTask = require('../tasks/schematic-get-help-output').default;
166+
const getHelpOutputTask = new SchematicGetHelpOutputTask({
167+
ui: this.ui,
168+
project: this.project
169+
});
170+
return getHelpOutputTask.run({
171+
schematicName,
172+
collectionName,
173+
nonSchematicOptions: this.availableOptions.filter((o: any) => !o.hidden)
174+
})
175+
.then((output: string[]) => {
176+
const outputLines = [
177+
cyan(`ng new ${cyan('[name]')} ${cyan('<options...>')}`),
178+
...output
179+
];
180+
return outputLines.join('\n');
181+
});
156182
}
157183
});
158184

packages/@angular/cli/tasks/schematic-get-help-output.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { cyan, grey } = chalk;
66
export interface SchematicGetHelpOptions {
77
collectionName: string;
88
schematicName: string;
9+
nonSchematicOptions: any[];
910
}
1011

1112
export interface SchematicAvailableOptions {
@@ -18,21 +19,21 @@ export interface SchematicAvailableOptions {
1819
}
1920

2021
export default Task.extend({
21-
run: function ({schematicName, collectionName}: SchematicGetHelpOptions):
22-
Promise<SchematicAvailableOptions[]> {
22+
run: function ({schematicName, collectionName, nonSchematicOptions}: SchematicGetHelpOptions):
23+
Promise<string[]> {
2324

2425
const SchematicGetOptionsTask = require('./schematic-get-options').default;
2526
const getOptionsTask = new SchematicGetOptionsTask({
2627
ui: this.ui,
2728
project: this.project
2829
});
29-
return getOptionsTask.run({
30+
return Promise.all([getOptionsTask.run({
3031
schematicName: schematicName,
3132
collectionName: collectionName,
32-
})
33-
.then((availableOptions: SchematicAvailableOptions[]) => {
33+
}), nonSchematicOptions])
34+
.then(([availableOptions, nonSchematicOptions]: [SchematicAvailableOptions[], any[]]) => {
3435
const output: string[] = [];
35-
availableOptions
36+
[...(nonSchematicOptions || []), ...availableOptions]
3637
.filter(opt => opt.name !== 'name')
3738
.forEach(opt => {
3839
let text = cyan(` --${opt.name}`);
@@ -48,7 +49,7 @@ export default Task.extend({
4849
output.push(text);
4950
if (opt.aliases && opt.aliases.length > 0) {
5051
const aliasText = opt.aliases.reduce(
51-
(acc, curr) => {
52+
(acc: string, curr: string) => {
5253
return acc + ` -${curr}`;
5354
},
5455
'');

0 commit comments

Comments
 (0)