Skip to content

Commit 706545d

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

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

addon/ng2/commands/help.ts

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

addon/ng2/index.js

Lines changed: 1 addition & 0 deletions
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)