Skip to content

Commit ec8fe64

Browse files
committed
bug(help): hide ember-cli commands when running help
Fixes: #1807
1 parent 78b0126 commit ec8fe64

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

addon/ng2/commands/help.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
const Command = require('ember-cli/lib/models/command');
5+
const EmberHelpCommand = require('ember-cli/lib/commands/help');
6+
const stringUtils = require('ember-cli-string-utils');
7+
const lookupCommand = require('ember-cli/lib/cli/lookup-command');
8+
9+
const commandsToIgnore = [
10+
'help',
11+
'easter-egg',
12+
'completion',
13+
'github-pages-deploy'
14+
]
15+
16+
const HelpCommand = Command.extend({
17+
name: 'help',
18+
description: 'Shows help for the CLI',
19+
works: 'outsideProject',
20+
21+
availableOptions: [],
22+
23+
run: function (commandOptions: any) {
24+
let commandFiles = fs.readdirSync(__dirname)
25+
.map(file => path.parse(file).name)
26+
.map(file => file.toLowerCase());
27+
28+
commandFiles = commandFiles.filter(file => {
29+
return commandsToIgnore.indexOf(file) < 0;
30+
});
31+
32+
let commandMap = commandFiles.reduce((acc: any, curr: string) => {
33+
let classifiedName = stringUtils.classify(curr);
34+
let defaultImport = require(`./${curr}`).default
35+
36+
acc[classifiedName] = defaultImport;
37+
38+
return acc;
39+
}, {});
40+
41+
commandFiles.forEach(cmd => {
42+
let Command = lookupCommand(commandMap, cmd);
43+
44+
let command = new Command({
45+
ui: this.ui,
46+
project: this.project,
47+
commands: this.commands,
48+
tasks: this.tasks
49+
});
50+
51+
this.ui.writeLine(command.printBasicHelp(commandOptions));
52+
})
53+
}
54+
});
55+
56+
HelpCommand.overrideCore = true;
57+
export default HelpCommand;

addon/ng2/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
'serve': require('./commands/serve').default,
1717
'new': require('./commands/new').default,
1818
'generate': require('./commands/generate').default,
19+
'help': require('./commands/help').default,
1920
'init': require('./commands/init').default,
2021
'test': require('./commands/test').default,
2122
'e2e': require('./commands/e2e').default,

0 commit comments

Comments
 (0)