[pack installer] renamed existing files

This commit is contained in:
Jim Unger 2016-03-03 12:52:12 -06:00
parent f6c48779dc
commit fa1fd274b4
26 changed files with 88 additions and 172 deletions

View file

@ -15,7 +15,6 @@ program
// attach commands
require('./serve/serve')(program);
require('./plugin/plugin')(program);
program
.command('help <command>')

40
src/cli_plugin/cli.js Normal file
View file

@ -0,0 +1,40 @@
import _ from 'lodash';
import pkg from '../utils/packageJson';
import Command from '../cli/Command';
let argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
let program = new Command('bin/kibana-plugin');
program
.version(pkg.version)
.description(
'Kibana is an open source (Apache Licensed), browser ' +
'based analytics and search dashboard for Elasticsearch.'
);
require('./list')(program);
require('./install')(program);
require('./remove')(program);
program
.command('help <command>')
.description('Get the help for a specific command')
.action(function (cmdName) {
var cmd = _.find(program.commands, { _name: cmdName });
if (!cmd) return this.error(`unknown command ${cmdName}`);
cmd.help();
});
program
.command('*', null, { noHelp: true })
.action(function (cmd, options) {
program.error(`unknown command ${cmd}`);
});
// check for no command name
var subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
if (!subCommand) {
program.defaultHelp();
}
program.parse(argv);

View file

@ -2,4 +2,4 @@
// before calling babel/register
const babelOptions = require('../optimize/babelOptions').node;
require('babel/register')(babelOptions);
require('./plugin');
require('./cli');

View file

@ -1,31 +0,0 @@
import expect from 'expect.js';
import fileType, { ZIP, TAR } from '../file_type';
describe('kibana cli', function () {
describe('file_type', function () {
it('returns ZIP for .zip filename', function () {
const type = fileType('wat.zip');
expect(type).to.equal(ZIP);
});
it('returns TAR for .tar.gz filename', function () {
const type = fileType('wat.tar.gz');
expect(type).to.equal(TAR);
});
it('returns TAR for .tgz filename', function () {
const type = fileType('wat.tgz');
expect(type).to.equal(TAR);
});
it('returns undefined for unknown file type', function () {
const type = fileType('wat.unknown');
expect(type).to.equal(undefined);
});
it('accepts paths', function () {
const type = fileType('/some/path/to/wat.zip');
expect(type).to.equal(ZIP);
});
it('accepts urls', function () {
const type = fileType('http://example.com/wat.zip');
expect(type).to.equal(ZIP);
});
});
});

View file

@ -1,34 +0,0 @@
import zlib from 'zlib';
import fs from 'fs';
import tar from 'tar';
async function extractArchive(settings) {
await new Promise((resolve, reject) => {
const gunzip = zlib.createGunzip();
const tarExtract = new tar.Extract({ path: settings.workingPath, strip: 1 });
const readStream = fs.createReadStream(settings.tempArchiveFile);
readStream.on('error', reject);
gunzip.on('error', reject);
tarExtract.on('error', reject);
readStream
.pipe(gunzip)
.pipe(tarExtract);
tarExtract.on('finish', resolve);
});
}
export default async function extractTarball(settings, logger) {
try {
logger.log('Extracting plugin archive');
await extractArchive(settings);
logger.log('Extraction complete');
} catch (err) {
logger.error(err);
throw new Error('Error extracting plugin archive');
}
};

View file

@ -1,14 +0,0 @@
export const TAR = '.tar.gz';
export const ZIP = '.zip';
export default function fileType(filename) {
if (/\.zip$/i.test(filename)) {
return ZIP;
}
if (/\.tar\.gz$/i.test(filename)) {
return TAR;
}
if (/\.tgz$/i.test(filename)) {
return TAR;
}
}

View file

@ -0,0 +1,47 @@
import fromRoot from '../../utils/fromRoot';
import install from './install';
import Logger from '../lib/logger';
import pkg from '../../utils/packageJson';
import { parse, parseMilliseconds } from './settings';
export default function pluginInstall(program) {
function processCommand(command, options) {
let settings;
try {
settings = parse(command, options, pkg);
} 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);
install(settings, logger);
}
program
.command('install <plugin/url>')
.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(
'-t, --timeout <duration>',
'Length of time before failing; 0 for never fail',
parseMilliseconds
)
.option(
'-d, --plugin-dir <path>',
'The path to the directory where plugins are stored',
fromRoot('installedPlugins')
)
.description('Install a plugin',
`Common examples:
install xpack
install file:///Path/to/my/xpack.zip
install https://path.to/my/xpack.zip`)
.action(processCommand);
};

View file

@ -1,16 +0,0 @@
import zipExtract from './extractors/zip';
import tarGzExtract from './extractors/tar_gz';
import { ZIP, TAR } from './file_type';
export default function extractArchive(settings, logger, archiveType) {
switch (archiveType) {
case ZIP:
return zipExtract(settings, logger);
break;
case TAR:
return tarGzExtract(settings, logger);
break;
default:
throw new Error('Unsupported archive format.');
}
};

View file

@ -1,75 +0,0 @@
import fromRoot from '../../utils/from_root';
import settingParser from './setting_parser';
import installer from './plugin_installer';
import remover from './plugin_remover';
import lister from './plugin_lister';
import pluginLogger from './plugin_logger';
export default function pluginCli(program) {
function processCommand(command, options) {
let settings;
try {
settings = settingParser(command).parse();
} catch (ex) {
//The logger has not yet been initialized.
console.error(ex.message);
process.exit(64); // eslint-disable-line no-process-exit
}
const logger = pluginLogger(settings);
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')
.option(
'-c, --config <path>',
'Path to the config file',
fromRoot('config/kibana.yml')
)
.option(
'-t, --timeout <duration>',
'Length of time before failing; 0 for never fail',
settingParser.parseMilliseconds
)
.option(
'-d, --plugin-dir <path>',
'The path to the directory where plugins are stored',
fromRoot('installedPlugins')
)
.description(
'Maintain Plugins',
`
Common examples:
-i username/sample
attempts to download the latest version from the following url:
https://download.elastic.co/username/sample/sample-latest.tar.gz
-i username/sample/v1.1.1
attempts to download version v1.1.1 from the following url:
https://download.elastic.co/username/sample/sample-v1.1.1.tar.gz
-i sample -u http://www.example.com/other_name.tar.gz
attempts to download from the specified url,
and installs the plugin found at that url as "sample"
`
)
.action(processCommand);
};