Skip to content

Commit 27106b6

Browse files
Broccohansl
authored andcommitted
fix(@angular/cli): fix ng help.
fixes #9412
1 parent f7090de commit 27106b6

File tree

1 file changed

+24
-58
lines changed
  • packages/@angular/cli/commands

1 file changed

+24
-58
lines changed

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

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import chalk from 'chalk';
12
import * as fs from 'fs';
23
import * as path from 'path';
34

5+
const { cyan } = chalk;
46
const Command = require('../ember-cli/lib/models/command');
57
const stringUtils = require('ember-cli-string-utils');
68
const lookupCommand = require('../ember-cli/lib/cli/lookup-command');
@@ -10,19 +12,11 @@ const HelpCommand = Command.extend({
1012
description: 'Shows help for the CLI.',
1113
works: 'everywhere',
1214

13-
availableOptions: [
14-
{
15-
name: 'short',
16-
type: Boolean,
17-
default: false,
18-
aliases: ['s'],
19-
description: 'Display command name and description only.'
20-
},
21-
],
15+
availableOptions: [],
2216

23-
anonymousOptions: ['command-name (Default: all)'],
17+
anonymousOptions: [],
2418

25-
run: function (commandOptions: any, rawArgs: any) {
19+
run: function (_commandOptions: any, _rawArgs: any) {
2620
let commandFiles = fs.readdirSync(__dirname)
2721
// Remove files that are not JavaScript or Typescript
2822
.filter(file => file.match(/\.(j|t)s$/) && !file.match(/\.d.ts$/))
@@ -38,54 +32,26 @@ const HelpCommand = Command.extend({
3832
return acc;
3933
}, {});
4034

41-
if (rawArgs.indexOf('all') !== -1) {
42-
rawArgs = []; // just act as if command not specified
43-
}
44-
45-
commandFiles.forEach(cmd => {
46-
const Command = lookupCommand(commandMap, cmd);
47-
48-
const command = new Command({
49-
ui: this.ui,
50-
project: this.project,
51-
commands: this.commands,
52-
tasks: this.tasks
53-
});
54-
55-
if (command.hidden || command.unknown) {
56-
return;
57-
}
58-
59-
if (rawArgs.length > 0) {
60-
let commandInput = rawArgs[0];
61-
const aliases = Command.prototype.aliases;
62-
if (aliases && aliases.indexOf(commandInput) > -1) {
63-
commandInput = Command.prototype.name;
64-
}
65-
66-
if (cmd === commandInput) {
67-
if (commandOptions.short) {
68-
this.ui.writeLine(command.printShortHelp(commandOptions));
69-
} else if (command.printDetailedHelp(commandOptions, rawArgs)) {
70-
const result = command.printDetailedHelp(commandOptions, rawArgs);
71-
if (result instanceof Promise) {
72-
result.then(r => this.ui.writeLine(r));
73-
} else {
74-
this.ui.writeLine(result);
75-
}
76-
} else {
77-
this.ui.writeLine(command.printBasicHelp(commandOptions));
78-
}
79-
}
80-
} else {
81-
if (commandOptions.short) {
82-
this.ui.writeLine(command.printShortHelp(commandOptions));
83-
} else {
84-
this.ui.writeLine(command.printBasicHelp(commandOptions));
85-
}
86-
}
87-
35+
const commands = commandFiles
36+
.map(commandFile => {
37+
const Command = lookupCommand(commandMap, commandFile);
38+
39+
const cmd = new Command({
40+
ui: this.ui,
41+
project: this.project,
42+
commands: this.commands,
43+
tasks: this.tasks
44+
});
45+
46+
return cmd;
47+
})
48+
.filter(cmd => !cmd.hidden && !cmd.unknown)
49+
.map(cmd => ({ name: cmd.name, description: cmd.description }));
50+
this.ui.writeLine(`Available Commands:`);
51+
commands.forEach(cmd => {
52+
this.ui.writeLine(` ${cyan(cmd.name)} ${cmd.description}`);
8853
});
54+
this.ui.writeLine(`\nFor more detailed help run "ng [command name] --help"`);
8955
}
9056
});
9157

0 commit comments

Comments
 (0)