"use strict";
/**
 * penguins-eggs
 * command: wear.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const utils_1 = tslib_1.__importDefault(require("../../classes/utils"));
const path_1 = tslib_1.__importDefault(require("path"));
const fs_1 = tslib_1.__importDefault(require("fs"));
const tailor_1 = tslib_1.__importDefault(require("../../classes/tailor"));
/**
 *
 */
class Wear extends core_1.Command {
    async run() {
        const { argv, flags } = await this.parse(Wear);
        const verbose = flags.verbose;
        utils_1.default.titles(this.id + ' ' + this.argv);
        let no_accessories = false;
        if (flags.no_accessories) {
            no_accessories = true;
        }
        let no_firmwares = false;
        if (flags.no_firmwares) {
            no_firmwares = true;
        }
        let wardrobe = await utils_1.default.wardrobe();
        if (flags.wardrobe !== undefined) {
            wardrobe = flags.wardrobe;
        }
        wardrobe = `${path_1.default.resolve(process.cwd(), wardrobe)}/`;
        if (!fs_1.default.existsSync(wardrobe)) {
            utils_1.default.warning(`wardrobe: ${wardrobe} not found!`);
            process.exit();
        }
        console.log(chalk_1.default.green('wardrobe: ') + wardrobe);
        /**
         * costume
         */
        let costume = 'costumes/colibri';
        if (this.argv['0'] !== undefined) {
            costume = this.argv['0']; // 12345678                               12345678901                              1234567
            if (costume.slice(0, 8) !== 'costumes' && costume.slice(0, 11) !== 'accessories' && costume.slice(0, 7) !== 'servers') {
                costume = `costumes/${costume}`;
            }
        }
        costume = wardrobe + costume;
        console.log(costume);
        if (!fs_1.default.existsSync(costume)) {
            utils_1.default.warning(`costume not found in : ${costume}!`);
            process.exit();
        }
        if (await utils_1.default.customConfirm(`Prepare your costume: ${costume}? Select yes to continue...`)) {
            if (utils_1.default.isRoot()) {
                const tailor = new tailor_1.default(costume);
                await tailor.prepare(verbose, no_accessories, no_firmwares);
            }
            else {
                utils_1.default.useRoot(this.id);
            }
        }
        else {
            console.log('costume ' + chalk_1.default.cyan(costume) + ' not found in wardrobe: ' + chalk_1.default.green(wardrobe));
        }
    }
}
Wear.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    no_accessories: core_1.Flags.boolean({ char: 'a', description: 'not install accessories' }),
    no_firmwares: core_1.Flags.boolean({ char: 'f', description: 'not install firmwares' }),
    verbose: core_1.Flags.boolean({ char: 'v' }),
    wardrobe: core_1.Flags.string({ char: 'w', description: 'wardrobe' }),
};
Wear.description = 'wear costume/accessories from wardrobe';
Wear.args = [{ name: 'costume', description: 'costume', required: false }];
Wear.examples = [
    'sudo eggs wardrobe wear duck',
    'sudo eggs wardrobe wear accessories/firmwares',
    'sudo eggs wardrobe wear wagtail/waydroid',
];
exports.default = Wear;
