From 706545d7d4c44c05ee6adfadb8c1e20b49e8233a Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Fri, 9 Sep 2016 23:31:34 -0400 Subject: [PATCH] bug(help): hide ember-cli commands when running help Fixes: #1807 --- addon/ng2/commands/help.ts | 56 ++++++++++++++++++++++++++++++++++++++ addon/ng2/index.js | 1 + 2 files changed, 57 insertions(+) create mode 100644 addon/ng2/commands/help.ts diff --git a/addon/ng2/commands/help.ts b/addon/ng2/commands/help.ts new file mode 100644 index 000000000000..06c5773ba1c2 --- /dev/null +++ b/addon/ng2/commands/help.ts @@ -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; diff --git a/addon/ng2/index.js b/addon/ng2/index.js index 58c02dc47fa7..218588d30f34 100644 --- a/addon/ng2/index.js +++ b/addon/ng2/index.js @@ -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,