Skip to content

Commit

Permalink
Adding CLI option for listing plugins
Browse files Browse the repository at this point in the history
Fixes #5920
  • Loading branch information
ycombinator authored and epixa committed Jan 16, 2016
1 parent cf314f9 commit ef68493
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/cli/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fromRoot = utils('fromRoot');
const settingParser = require('./setting_parser');
const installer = require('./plugin_installer');
const remover = require('./plugin_remover');
const lister = require('./plugin_lister');
const pluginLogger = require('./plugin_logger');

export default function pluginCli(program) {
Expand All @@ -24,12 +25,17 @@ export default function pluginCli(program) {
if (settings.action === 'remove') {
remover.remove(settings, logger);
}
if (settings.action === 'list') {
lister.list(settings, logger);
}

}

program
.command('plugin')
.option('-i, --install <org>/<plugin>/<version>', 'The plugin to install')
.option('-r, --remove <plugin>', 'The plugin to remove')
.option('-l, --list', 'List installed plugins')
.option('-q, --quiet', 'Disable all process messaging except errors')
.option('-s, --silent', 'Disable all process messaging')
.option('-u, --url <url>', 'Specify download url')
Expand Down
18 changes: 18 additions & 0 deletions src/cli/plugin/plugin_lister.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');

module.exports = {
list: list
};

function list(settings, logger) {
fs.readdir(settings.pluginDir, function (err, files) {

var pluginFiles = files.filter(function (file) {
return file[0] !== '.';
});

pluginFiles.forEach(function (pluginFile) {
logger.log(pluginFile);
});
});
}
8 changes: 6 additions & 2 deletions src/cli/plugin/setting_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ export default function createSettingParser(options) {
settings.package = parts.shift();
}

if (!settings.action || (options.install && options.remove)) {
throw new Error('Please specify either --install or --remove.');
if (options.list) {
settings.action = 'list';
}

if (!settings.action || (options.install && options.remove && options.list)) {
throw new Error('Please specify either --install, --remove, or --list.');
}

settings.pluginDir = options.pluginDir;
Expand Down

0 comments on commit ef68493

Please sign in to comment.