Skip to content

Commit 80275e5

Browse files
catullfilipesilva
authored andcommitted
feat(@angular/cli): Implement request 7141 - Short list of cli commands
When calling ng help -s / --short one gets a shorter output; basically only ng + command, followed by the command's description. No breaking change, as it introduces a new flag.
1 parent 52f9b80 commit 80275e5

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ const HelpCommand = Command.extend({
1010
description: 'Shows help for the CLI.',
1111
works: 'everywhere',
1212

13-
availableOptions: [],
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+
],
1422

1523
anonymousOptions: ['command-name (Default: all)'],
1624

@@ -56,14 +64,20 @@ const HelpCommand = Command.extend({
5664
}
5765

5866
if (cmd === commandInput) {
59-
if (command.printDetailedHelp(commandOptions)) {
67+
if (commandOptions.short) {
68+
this.ui.writeLine(command.printShortHelp(commandOptions));
69+
} else if (command.printDetailedHelp(commandOptions)) {
6070
this.ui.writeLine(command.printDetailedHelp(commandOptions));
6171
} else {
6272
this.ui.writeLine(command.printBasicHelp(commandOptions));
6373
}
6474
}
6575
} else {
66-
this.ui.writeLine(command.printBasicHelp(commandOptions));
76+
if (commandOptions.short) {
77+
this.ui.writeLine(command.printShortHelp(commandOptions));
78+
} else {
79+
this.ui.writeLine(command.printBasicHelp(commandOptions));
80+
}
6781
}
6882

6983
});

packages/@angular/cli/ember-cli/lib/models/command.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,32 @@ let Command = CoreObject.extend({
550550

551551
_printCommand: printCommand,
552552

553+
/**
554+
Prints short help for the command.
555+
Short help looks like this:
556+
ng generate <blueprint> <options...>
557+
Generates new code from blueprints
558+
aliases: g
559+
The default implementation is designed to cover all bases
560+
but may be overridden if necessary.
561+
@method printShortHelp
562+
*/
563+
printShortHelp() {
564+
// ng command-name
565+
let output;
566+
if (this.isRoot) {
567+
output = `Usage: ${this.name}`;
568+
} else {
569+
output = `ng ${this.name}`;
570+
}
571+
572+
output += EOL;
573+
output += ` ${this.description}`;
574+
output += EOL;
575+
576+
return output;
577+
},
578+
553579
/**
554580
Prints basic help for the command.
555581
Basic help looks like this:
@@ -559,7 +585,7 @@ let Command = CoreObject.extend({
559585
--dry-run (Default: false)
560586
--verbose (Default: false)
561587
The default implementation is designed to cover all bases
562-
but may be overriden if necessary.
588+
but may be overridden if necessary.
563589
@method printBasicHelp
564590
*/
565591
printBasicHelp() {

0 commit comments

Comments
 (0)