Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to list installed plugins from CLI #5920

Merged
merged 14 commits into from
Jan 16, 2016
Merged
17 changes: 12 additions & 5 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 @@ -18,18 +19,24 @@ export default function pluginCli(program) {

const logger = pluginLogger(settings);

if (settings.action === 'install') {
installer.install(settings, logger);
}
if (settings.action === 'remove') {
remover.remove(settings, logger);
switch (settings.action) {
case 'install':
installer.install(settings, logger);
break;
case 'remove':
remover.remove(settings, logger);
break;
case 'list':
lister.list(settings, logger);
break;
}
}

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
8 changes: 8 additions & 0 deletions src/cli/plugin/plugin_lister.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require('fs');

export function list(settings, logger) {
fs.readdirSync(settings.pluginDir)
.forEach(function (pluginFile) {
logger.log(pluginFile);
});
}
13 changes: 11 additions & 2 deletions src/cli/plugin/setting_parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { resolve } = require('path');
const expiry = require('expiry-js');
import intersection from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be import { intersection } from 'lodash'; The current line should error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction, the current line itself wouldn't error, however intersection would be the lodash constructor itself rather than the intersection function from within lodash.


export default function createSettingParser(options) {
function parseMilliseconds(val) {
Expand All @@ -22,6 +23,10 @@ export default function createSettingParser(options) {
return 'https://download.elastic.co/' + settings.organization + '/' + settings.package + '/' + filename;
}

function areMultipleOptionsChosen(options, choices) {
return intersection(Object.keys(options), choices).length > 1;
}

function parse() {
let parts;
let settings = {
Expand Down Expand Up @@ -84,8 +89,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 || areMultipleOptionsChosen(options, [ 'install', 'remove', 'list' ])) {
throw new Error('Please specify either --install, --remove, or --list.');
}

settings.pluginDir = options.pluginDir;
Expand Down