mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[pack installer] updated remove command
This commit is contained in:
parent
7401cac179
commit
8f4ea5678f
5 changed files with 222 additions and 8 deletions
56
src/cli_plugin/remove/__tests__/remove.js
Normal file
56
src/cli_plugin/remove/__tests__/remove.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import glob from 'glob';
|
||||
import rimraf from 'rimraf';
|
||||
import mkdirp from 'mkdirp';
|
||||
import Logger from '../../lib/logger';
|
||||
import remove from '../remove';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('kibana cli', function () {
|
||||
|
||||
describe('plugin lister', function () {
|
||||
|
||||
const pluginDir = join(__dirname, '.test.data');
|
||||
let logger;
|
||||
|
||||
const settings = {
|
||||
pluginDir: pluginDir
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
logger = new Logger(settings);
|
||||
sinon.stub(logger, 'log');
|
||||
sinon.stub(logger, 'error');
|
||||
rimraf.sync(pluginDir);
|
||||
mkdirp.sync(pluginDir);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
logger.log.restore();
|
||||
logger.error.restore();
|
||||
rimraf.sync(pluginDir);
|
||||
});
|
||||
|
||||
it('log a message if the plugin is not installed.', function () {
|
||||
settings.pluginPath = join(pluginDir, 'foo');
|
||||
remove(settings, logger);
|
||||
|
||||
expect(logger.log.firstCall.args[0]).to.match(/not installed/i);
|
||||
});
|
||||
|
||||
it('delete the specified folder.', function () {
|
||||
settings.pluginPath = join(pluginDir, 'foo');
|
||||
mkdirp.sync(join(pluginDir, 'foo'));
|
||||
mkdirp.sync(join(pluginDir, 'bar'));
|
||||
|
||||
remove(settings, logger);
|
||||
|
||||
const files = glob.sync('**/*', { cwd: pluginDir });
|
||||
const expected = ['bar'];
|
||||
expect(files.sort()).to.eql(expected.sort());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
108
src/cli_plugin/remove/__tests__/settings.js
Normal file
108
src/cli_plugin/remove/__tests__/settings.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
import path from 'path';
|
||||
import expect from 'expect.js';
|
||||
|
||||
const utils = require('requirefrom')('src/utils');
|
||||
const fromRoot = utils('fromRoot');
|
||||
import { resolve } from 'path';
|
||||
import { parseMilliseconds, parse } from '../settings';
|
||||
|
||||
describe('kibana cli', function () {
|
||||
|
||||
describe('plugin installer', function () {
|
||||
|
||||
describe('command line option parsing', function () {
|
||||
|
||||
describe('parse function', function () {
|
||||
|
||||
const command = 'plugin name';
|
||||
let options = {};
|
||||
const kbnPackage = { version: 1234 };
|
||||
beforeEach(function () {
|
||||
options = { pluginDir: fromRoot('installedPlugins') };
|
||||
});
|
||||
|
||||
describe('quiet option', function () {
|
||||
|
||||
it('should default to false', function () {
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.quiet).to.be(false);
|
||||
});
|
||||
|
||||
it('should set settings.quiet property to true', function () {
|
||||
options.quiet = true;
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.quiet).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('silent option', function () {
|
||||
|
||||
it('should default to false', function () {
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.silent).to.be(false);
|
||||
});
|
||||
|
||||
it('should set settings.silent property to true', function () {
|
||||
options.silent = true;
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.silent).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('config option', function () {
|
||||
|
||||
it('should default to ZLS', function () {
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.config).to.be('');
|
||||
});
|
||||
|
||||
it('should set settings.config property', function () {
|
||||
options.config = 'foo bar baz';
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.config).to.be('foo bar baz');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('pluginDir option', function () {
|
||||
|
||||
it('should default to installedPlugins', function () {
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.pluginDir).to.be(fromRoot('installedPlugins'));
|
||||
});
|
||||
|
||||
it('should set settings.config property', function () {
|
||||
options.pluginDir = 'foo bar baz';
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.pluginDir).to.be('foo bar baz');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('command value', function () {
|
||||
|
||||
it('should set settings.plugin property', function () {
|
||||
const settings = parse(command, options, kbnPackage);
|
||||
|
||||
expect(settings.plugin).to.be(command);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
39
src/cli_plugin/remove/index.js
Normal file
39
src/cli_plugin/remove/index.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import fromRoot from '../../utils/fromRoot';
|
||||
import remove from './remove';
|
||||
import Logger from '../lib/logger';
|
||||
import { parse } from './settings';
|
||||
|
||||
export default function pluginList(program) {
|
||||
function processCommand(command, options) {
|
||||
let settings;
|
||||
try {
|
||||
settings = parse(command, options);
|
||||
} catch (ex) {
|
||||
//The logger has not yet been initialized.
|
||||
console.error(ex.message);
|
||||
process.exit(64); // eslint-disable-line no-process-exit
|
||||
}
|
||||
|
||||
const logger = new Logger(settings);
|
||||
remove(settings, logger);
|
||||
}
|
||||
|
||||
program
|
||||
.command('remove <plugin>')
|
||||
.option('-q, --quiet', 'Disable all process messaging except errors')
|
||||
.option('-s, --silent', 'Disable all process messaging')
|
||||
.option(
|
||||
'-c, --config <path>',
|
||||
'Path to the config file',
|
||||
fromRoot('config/kibana.yml')
|
||||
)
|
||||
.option(
|
||||
'-d, --plugin-dir <path>',
|
||||
'The path to the directory where plugins are stored',
|
||||
fromRoot('installedPlugins')
|
||||
)
|
||||
.description('Remove a plugin',
|
||||
`Common examples:
|
||||
remove xpack`)
|
||||
.action(processCommand);
|
||||
};
|
|
@ -1,23 +1,19 @@
|
|||
import fs from 'fs';
|
||||
import rimraf from 'rimraf';
|
||||
|
||||
module.exports = {
|
||||
remove: remove
|
||||
};
|
||||
|
||||
function remove(settings, logger) {
|
||||
export default function remove(settings, logger) {
|
||||
try {
|
||||
try {
|
||||
fs.statSync(settings.pluginPath);
|
||||
} catch (e) {
|
||||
logger.log(`Plugin ${settings.package} does not exist`);
|
||||
logger.log(`Plugin ${settings.plugin} is not installed`);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log(`Removing ${settings.package}...`);
|
||||
logger.log(`Removing ${settings.plugin}...`);
|
||||
rimraf.sync(settings.pluginPath);
|
||||
} catch (err) {
|
||||
logger.error(`Unable to remove plugin "${settings.package}" because of error: "${err.message}"`);
|
||||
logger.error(`Unable to remove plugin "${settings.plugin}" because of error: "${err.message}"`);
|
||||
process.exit(74); // eslint-disable-line no-process-exit
|
||||
}
|
||||
}
|
||||
|
|
15
src/cli_plugin/remove/settings.js
Normal file
15
src/cli_plugin/remove/settings.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { resolve } from 'path';
|
||||
|
||||
export function parse(command, options) {
|
||||
const settings = {
|
||||
quiet: options.quiet ? options.quiet : false,
|
||||
silent: options.silent ? options.silent : false,
|
||||
config: options.config ? options.config : '',
|
||||
pluginDir: options.pluginDir ? options.pluginDir : '',
|
||||
plugin: command
|
||||
};
|
||||
|
||||
settings.pluginPath = resolve(settings.pluginDir, settings.plugin);
|
||||
|
||||
return settings;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue