Skip to content

Commit 169d327

Browse files
Charles Lydingfilipesilva
Charles Lyding
authored andcommitted
refactor(@angular/cli): support hidden commands and options
1 parent 6825de8 commit 169d327

File tree

7 files changed

+32
-22
lines changed

7 files changed

+32
-22
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ export interface CompletionCommandOptions {
3838
zsh?: boolean;
3939
}
4040

41-
const commandsToIgnore = [
42-
'destroy',
43-
'easter-egg',
44-
'init'
45-
];
46-
4741
const optsNg: string[] = [];
4842

4943
const CompletionCommand = Command.extend({
@@ -80,9 +74,6 @@ const CompletionCommand = Command.extend({
8074
const commandFiles = fs.readdirSync(__dirname)
8175
.filter(file => file.match(/\.(j|t)s$/) && !file.match(/\.d.ts$/))
8276
.map(file => path.parse(file).name)
83-
.filter(file => {
84-
return commandsToIgnore.indexOf(file) < 0;
85-
})
8677
.map(file => file.toLowerCase());
8778

8879
const commandMap = commandFiles.reduce((acc: any, curr: string) => {
@@ -107,6 +98,10 @@ const CompletionCommand = Command.extend({
10798
tasks: this.tasks
10899
});
109100

101+
if (command.hidden || command.unknown) {
102+
return;
103+
}
104+
110105
optsNg.push(command.name);
111106
com.push(command.name);
112107

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DestroyCommand = Command.extend({
66
name: 'destroy',
77
aliases: ['d'],
88
works: 'insideProject',
9+
hidden: true,
910

1011
anonymousOptions: [
1112
'<blueprint>'

packages/@angular/cli/commands/easter-egg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function pickOne(of: string[]): string {
1111
const MakeThisAwesomeCommand = Command.extend({
1212
name: 'make-this-awesome',
1313
works: 'insideProject',
14+
hidden: true,
1415

1516
run: function (commandOptions: any, rawArgs: string[]): Promise<void> {
1617
(this as any)[stringUtils.camelize(this.name)](commandOptions, rawArgs);

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ const Command = require('../ember-cli/lib/models/command');
55
const stringUtils = require('ember-cli-string-utils');
66
const lookupCommand = require('../ember-cli/lib/cli/lookup-command');
77

8-
const commandsToIgnore = [
9-
'easter-egg',
10-
'init',
11-
'destroy'
12-
];
13-
148
const HelpCommand = Command.extend({
159
name: 'help',
1610
description: 'Shows help for the CLI.',
@@ -27,10 +21,6 @@ const HelpCommand = Command.extend({
2721
.map(file => path.parse(file).name)
2822
.map(file => file.toLowerCase());
2923

30-
commandFiles = commandFiles.filter(file => {
31-
return commandsToIgnore.indexOf(file) < 0;
32-
});
33-
3424
let commandMap = commandFiles.reduce((acc: any, curr: string) => {
3525
let classifiedName = stringUtils.classify(curr);
3626
let defaultImport = require(`./${curr}`).default;
@@ -45,15 +35,19 @@ const HelpCommand = Command.extend({
4535
}
4636

4737
commandFiles.forEach(cmd => {
48-
let Command = lookupCommand(commandMap, cmd);
38+
const Command = lookupCommand(commandMap, cmd);
4939

50-
let command = new Command({
40+
const command = new Command({
5141
ui: this.ui,
5242
project: this.project,
5343
commands: this.commands,
5444
tasks: this.tasks
5545
});
5646

47+
if (command.hidden || command.unknown) {
48+
return;
49+
}
50+
5751
if (rawArgs.length > 0) {
5852
let commandInput = rawArgs[0];
5953
const aliases = Command.prototype.aliases;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const InitCommand: any = Command.extend({
44
name: 'init',
55
description: 'Creates a new Angular CLI project in the current folder.',
66
works: 'everywhere',
7+
hidden: true,
78

89
availableOptions: [
910
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },

packages/@angular/cli/ember-cli/lib/utilities/print-command.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module.exports = function(initialMargin, shouldDescriptionBeGrey) {
2222
}).join(' '));
2323
}
2424

25-
options = this.availableOptions;
25+
options = this.availableOptions
26+
.filter(function(option) { return !option.hidden; });
2627

2728
// <options...>
2829
if (options.length) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { oneLine } from 'common-tags';
2+
3+
import { silentNg } from '../../../utils/process';
4+
5+
6+
export default function() {
7+
return Promise.resolve()
8+
.then(() => silentNg('--help'))
9+
.then(({ stdout }) => {
10+
if (stdout.match(/(easter-egg)|(ng make-this-awesome)|(ng init)/)) {
11+
throw new Error(oneLine`
12+
Expected to not match "(easter-egg)|(ng make-this-awesome)|(ng init)"
13+
in help output.
14+
`);
15+
}
16+
});
17+
}

0 commit comments

Comments
 (0)