Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions addon/ng2/commands/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as fs from 'fs';
import * as path from 'path';

const Command = require('ember-cli/lib/models/command');
const stringUtils = require('ember-cli-string-utils');
const lookupCommand = require('ember-cli/lib/cli/lookup-command');

const commandsToIgnore = [
'help',
'easter-egg',
'completion',
'github-pages-deploy'
];

const HelpCommand = Command.extend({
name: 'help',
description: 'Shows help for the CLI',
works: 'outsideProject',

availableOptions: [],

run: function (commandOptions: any) {
let commandFiles = fs.readdirSync(__dirname)
.map(file => path.parse(file).name)
.map(file => file.toLowerCase());

commandFiles = commandFiles.filter(file => {
return commandsToIgnore.indexOf(file) < 0;
});

let commandMap = commandFiles.reduce((acc: any, curr: string) => {
let classifiedName = stringUtils.classify(curr);
let defaultImport = require(`./${curr}`).default;

acc[classifiedName] = defaultImport;

return acc;
}, {});

commandFiles.forEach(cmd => {
let Command = lookupCommand(commandMap, cmd);

let command = new Command({
ui: this.ui,
project: this.project,
commands: this.commands,
tasks: this.tasks
});

this.ui.writeLine(command.printBasicHelp(commandOptions));
});
}
});

HelpCommand.overrideCore = true;
export default HelpCommand;
1 change: 1 addition & 0 deletions addon/ng2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'serve': require('./commands/serve').default,
'new': require('./commands/new').default,
'generate': require('./commands/generate').default,
'help': require('./commands/help').default,
'init': require('./commands/init').default,
'test': require('./commands/test').default,
'e2e': require('./commands/e2e').default,
Expand Down