mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[pack installer] updated the list command
This commit is contained in:
parent
6830296e2e
commit
7401cac179
5 changed files with 152 additions and 3 deletions
61
src/cli_plugin/list/__tests__/list.js
Normal file
61
src/cli_plugin/list/__tests__/list.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import rimraf from 'rimraf';
|
||||
import mkdirp from 'mkdirp';
|
||||
import Logger from '../../lib/logger';
|
||||
import list from '../list';
|
||||
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('list all of the directories in the plugin folder', function () {
|
||||
mkdirp.sync(join(pluginDir, 'plugin1'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin2'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin3'));
|
||||
|
||||
list(settings, logger);
|
||||
|
||||
expect(logger.log.calledWith('plugin1')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin2')).to.be(true);
|
||||
expect(logger.log.calledWith('plugin3')).to.be(true);
|
||||
});
|
||||
|
||||
it('ignore folders that start with a period', function () {
|
||||
mkdirp.sync(join(pluginDir, '.foo'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin1'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin2'));
|
||||
mkdirp.sync(join(pluginDir, 'plugin3'));
|
||||
mkdirp.sync(join(pluginDir, '.bar'));
|
||||
|
||||
list(settings, logger);
|
||||
|
||||
expect(logger.log.calledWith('.foo')).to.be(false);
|
||||
expect(logger.log.calledWith('.bar')).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
46
src/cli_plugin/list/__tests__/settings.js
Normal file
46
src/cli_plugin/list/__tests__/settings.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
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 () {
|
||||
|
||||
let command;
|
||||
const options = {};
|
||||
beforeEach(function () {
|
||||
command = { pluginDir: fromRoot('installedPlugins') };
|
||||
});
|
||||
|
||||
describe('pluginDir option', function () {
|
||||
|
||||
it('should default to installedPlugins', function () {
|
||||
const settings = parse(command, options);
|
||||
|
||||
expect(settings.pluginDir).to.be(fromRoot('installedPlugins'));
|
||||
});
|
||||
|
||||
it('should set settings.config property', function () {
|
||||
command.pluginDir = 'foo bar baz';
|
||||
const settings = parse(command, options);
|
||||
|
||||
expect(settings.pluginDir).to.be('foo bar baz');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
30
src/cli_plugin/list/index.js
Normal file
30
src/cli_plugin/list/index.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import fromRoot from '../../utils/fromRoot';
|
||||
import list from './list';
|
||||
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);
|
||||
list(settings, logger);
|
||||
}
|
||||
|
||||
program
|
||||
.command('list')
|
||||
.option(
|
||||
'-d, --plugin-dir <path>',
|
||||
'The path to the directory where plugins are stored',
|
||||
fromRoot('installedPlugins')
|
||||
)
|
||||
.description('List installed plugins')
|
||||
.action(processCommand);
|
||||
};
|
|
@ -1,8 +1,11 @@
|
|||
import fs from 'fs';
|
||||
|
||||
export function list(settings, logger) {
|
||||
export default function list(settings, logger) {
|
||||
fs.readdirSync(settings.pluginDir)
|
||||
.forEach(function (pluginFile) {
|
||||
logger.log(pluginFile);
|
||||
.forEach((filename) => {
|
||||
if (filename[0] !== '.') {
|
||||
logger.log(filename);
|
||||
}
|
||||
});
|
||||
logger.log('');
|
||||
}
|
||||
|
|
9
src/cli_plugin/list/settings.js
Normal file
9
src/cli_plugin/list/settings.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { resolve } from 'path';
|
||||
|
||||
export function parse(command, options) {
|
||||
const settings = {
|
||||
pluginDir: command.pluginDir ? command.pluginDir : ''
|
||||
};
|
||||
|
||||
return settings;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue