copybase
Version:
Copy or backup databases quickly
59 lines (58 loc) • 2.68 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const helper_1 = require("./helper");
const moduleName = "copybase";
const config = (0, helper_1.loadConfig)(moduleName);
const program = new commander_1.Command();
function execAction(callback) {
return __awaiter(this, void 0, void 0, function* () {
if (!config) {
console.error(`Config not found. Create file .${moduleName}.(yaml|js|json)`);
return;
}
console.time("done");
yield callback();
console.timeEnd("done");
});
}
program
.name(moduleName)
.description("Copy quickly a database")
.version(require("../package.json").version);
program
.command("copy")
.argument("<fromDatabase>", "Database to copy")
.argument("<toDatabase>", "Destination Database")
.option("--verbose", "Verbose mode")
.description("Copy a database")
.action((fromDatabase, toDatabase, options) => execAction(() => (0, helper_1.copy)(config, { fromDatabase, toDatabase }, options)));
program
.command("list:tables")
.argument("<database>", "List tables")
.option("--verbose", "Verbose mode")
.description("List all tables in database")
.action((database, options) => execAction(() => (0, helper_1.listTables)(config, { database }, options)));
program
.command("backup")
.description("Backup a database")
.argument("<database>", "Database to backup")
.option("--verbose", "Verbose mode")
.action((database, options) => execAction(() => (0, helper_1.backup)(config, { database }, options)));
program
.command("restore")
.description("Restore a database")
.argument("<from>", "archive folder")
.argument("<toDatabase>", "Destination Database")
.option("--verbose", "Verbose mode")
.action((from, toDatabase, options) => execAction(() => (0, helper_1.restore)(config, { from, toDatabase }, options)));
program.parse(process.argv);