<commit_before>#! /usr/bin/env node

var program = require('commander');
var pack = require('./package.json');
var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');

/**
 * Docker Machine Import / Export
 *
 * @copyright 2016 Mumba Pty Ltd. All rights reserved.
 * @license   Apache-2.0
 */

//Setup our command line interactions
program
	.version(pack.version)
	.usage('[options]')
	.description('Import/Export docker-machines')
	.option('-x, --export [value]', 'export docker machine')
	.option('-i, --import [value]', 'import json encoded output from dmport export. NOTE! use eval $(dmport -i $ENVVAR_W_EXPORT_JSON) to set env vars for machine, certificates will also be written to file')
	.parse(process.argv);

//we require options so lets error out if we dont get them.
if (!program.export && !program.import) {
	console.error('An option is required');
	process.exit(9);
}

function getPaths(vars) {
	var machinepath, certPathArray, storepath, certpath;

	if (vars.indexOf('DOCKER_') === -1) {
		machinepath = path.join(process.env.HOME, '.docker', 'machine', 'machines', vars, path.sep);
		certpath = path.join(process.env.HOME, '.docker', 'machine', 'certs', path.sep);
		storepath = path.join(process.env.HOME, '.docker', 'machine', path.sep);

		if (!fs.existsSync(path.join(process.env.HOME, '.docker'))) {
			fs.mkdirSync(path.join(process.env.HOME, '.docker'));
		}

		if (!fs.existsSync(storepath)) {
			fs.mkdirSync(storepath);
		}

		if (!fs.existsSync(certpath)) {
			fs.mkdirSync(certpath);
		}

		if (!fs.existsSync(path.join(storepath, 'machines'))) {
			fs.mkdirSync(path.join(storepath, 'machines'));
		}

		if (!fs.existsSync(machinepath)) {
			fs.mkdirSync(machinepath);
		}
	} else {
		//this regex digs the path out of the environment variables
		machinepath = /DOCKER_CERT_PATH=(.*)/g.exec(vars)[1].replace(/['"]+/g, '');
		certPathArray = machinepath.split(path.sep);
		certPathArray.splice(-2, 2);
		storepath = certPathArray.join(path.sep);
		certPathArray.push("certs");
		certpath = certPathArray.join(path.sep);
	}

	return {"machine": machinepath, "cert": certpath, "store": storepath};
}

//start of the export method
if (program.export) {

	//since this is specific to docker-machine we are assuming its installed for exporting.
	exec('docker-machine env ' + program.export, function (error, stdout, stderr) {
		if (error) {
			console.error('exec error', error);
			return;<commit_msg>added --shell command for docker export<commit_after>#! /usr/bin/env node

var program = require('commander');
var pack = require('./package.json');
var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');
var exportCommand = "";

/**
 * Docker Machine Import / Export
 *
 * @copyright 2016 Mumba Pty Ltd. All rights reserved.
 * @license   Apache-2.0
 */

//Setup our command line interactions
program
	.version(pack.version)
	.usage('[options]')
	.description('Import/Export docker-machines')
	.option('-x, --export [value]', 'export docker machine')
	.option('-i, --import [value]', 'import json encoded output from dmport export. NOTE! use eval $(dmport -i $ENVVAR_W_EXPORT_JSON) to set env vars for machine, certificates will also be written to file')
	.option('-s, --shell [value]', 'sets the shell for docker-machine to use')
	.parse(process.argv);

//we require options so lets error out if we dont get them.
if (!program.export && !program.import) {
	console.error('An option is required');
	process.exit(9);
}

function getPaths(vars) {
	var machinepath, certPathArray, storepath, certpath;

	if (vars.indexOf('DOCKER_') === -1) {
		machinepath = path.join(process.env.HOME, '.docker', 'machine', 'machines', vars, path.sep);
		certpath = path.join(process.env.HOME, '.docker', 'machine', 'certs', path.sep);
		storepath = path.join(process.env.HOME, '.docker', 'machine', path.sep);

		if (!fs.existsSync(path.join(process.env.HOME, '.docker'))) {
			fs.mkdirSync(path.join(process.env.HOME, '.docker'));
		}

		if (!fs.existsSync(storepath)) {
			fs.mkdirSync(storepath);
		}

		if (!fs.existsSync(certpath)) {
			fs.mkdirSync(certpath);
		}

		if (!fs.existsSync(path.join(storepath, 'machines'))) {
			fs.mkdirSync(path.join(storepath, 'machines'));
		}

		if (!fs.existsSync(machinepath)) {
			fs.mkdirSync(machinepath);
		}
	} else {
		//this regex digs the path out of the environment variables
		machinepath = /DOCKER_CERT_PATH=(.*)/g.exec(vars)[1].replace(/['"]+/g, '');
		certPathArray = machinepath.split(path.sep);
		certPathArray.splice(-2, 2);
		storepath = certPathArray.join(path.sep);
		certPathArray.push("certs");
		certpath = certPathArray.join(path.sep);
	}

	return {"machine": machinepath, "cert": certpath, "store": storepath};
}

//start of the export method
if (program.export) {

	exportCommand = 'docker-machine env ' + program.export;

	if(program.shell){
		exportCommand = exportCommand + ' --shell ' + program.shell;
	}

	//since this is specific to docker-machine we are assuming its installed for exporting.
	exec(exportCommand, function (error, stdout, stderr) {
		if (error) {
			console.error('exec error', error);
			return;
{'fraction_non_alphanumeric': 0.16808510638297872, 'fraction_numerical': 0.00425531914893617, 'mean_word_length': 4.358549222797928, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5943651', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1693, 'n_words': 437}