"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * command: get.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
const core_1 = require("@oclif/core");
const utils_1 = tslib_1.__importDefault(require("../../classes/utils"));
// libraries
const utils_2 = require("../../lib/utils");
const path_1 = require("path");
/**
 *
 */
class Get extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(Get);
        let verbose = false;
        if (flags.verbose) {
            verbose = true;
        }
        const echo = utils_1.default.setEcho(verbose);
        utils_1.default.titles(this.id + ' ' + this.argv);
        let repo = 'https://github.com/pieroproietti/penguins-wardrobe';
        if (this.argv['0'] !== undefined) {
            repo = this.argv['0'];
        }
        // No sudo for get
        if (process.getuid && process.getuid() === 0) {
            utils_1.default.warning('You must run: eggs wardrobe get without sudo');
            process.exit(0);
        }
        const wardrobe = (0, path_1.basename)(repo); // ~/.eggs-wardrobe
        // git clone -b <branchname> --single-branch 
        // const result = await exec(`git clone -b devel --single-branch --depth 1 ${repo} ${await Utils.wardrobe()}`)
        const result = await (0, utils_2.exec)(`git clone --single-branch --depth 1 ${repo} ${await utils_1.default.wardrobe()}`);
        if (result.code === 0) {
            utils_1.default.warning(`you get new wardrobe from repo: ${repo} in ${await utils_1.default.wardrobe()}`);
        }
    }
}
Get.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    verbose: core_1.Flags.boolean({ char: 'v' }),
};
Get.args = [{ name: 'repo', description: 'repository to get', required: false }];
Get.description = 'get warorobe';
Get.examples = [
    'eggs wardrobe get',
    'eggs wardrobe get your-wardrobe',
];
exports.default = Get;
