"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * command: show.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
// libraries
const core_1 = require("@oclif/core");
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const distro_1 = tslib_1.__importDefault(require("../../classes/distro"));
const utils_1 = tslib_1.__importDefault(require("../../classes/utils"));
/**
 *
 */
class Show extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(Show);
        const verbose = flags.verbose;
        const json = flags.json;
        const echo = utils_1.default.setEcho(verbose);
        utils_1.default.titles(this.id + ' ' + this.argv);
        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'];
            if (costume.slice(0, 8) !== 'costumes' && costume.slice(0, 11) !== 'accessories' && costume.slice(0, 7) !== 'servers') {
                costume = `costumes/${costume}`;
            }
        }
        costume = wardrobe + costume;
        if (!fs_1.default.existsSync(costume)) {
            console.log(`costume: ${chalk_1.default.green(path_1.default.basename(costume))} not found in wardrobe: ${chalk_1.default.green(wardrobe)}`);
            process.exit();
        }
        /**
          * tailorList
          */
        let distro = new distro_1.default();
        let index = '';
        if (distro.distroLike === "Arch") {
            index = 'arch.yml';
        }
        else if (distro.distroLike === "Debian" || distro.distroLike === "Devuan") {
            index = 'debian.yml';
        }
        else if (distro.distroLike === "Debian") {
            index = 'ubuntu.yml';
        }
        const tailorList = `${costume}/${index}`;
        if (!fs_1.default.existsSync(tailorList)) {
            utils_1.default.warning(`index.yml not found in : ${costume}!`);
            process.exit();
        }
        const materials = js_yaml_1.default.load(fs_1.default.readFileSync(tailorList, 'utf-8'));
        if (json) {
            console.log(JSON.stringify(materials, null, ' '));
        }
        else {
            console.log(js_yaml_1.default.dump(materials));
        }
    }
}
Show.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    json: core_1.Flags.boolean({ char: 'j', description: 'output JSON' }),
    verbose: core_1.Flags.boolean({ char: 'v' }),
    wardrobe: core_1.Flags.string({ char: 'w', description: 'wardrobe' }),
};
Show.description = 'show costumes/accessories in wardrobe';
Show.args = [{ name: 'costume', description: 'costume', required: false }];
Show.example = [
    'eggs wardrobe show colibri',
    'eggs wardrobe show accessories/firmwares',
    'eggs wardrobe show accessories/',
];
exports.default = Show;
