"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * command: list.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"));
const path_1 = tslib_1.__importDefault(require("path"));
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
const fs_1 = tslib_1.__importDefault(require("fs"));
const distro_1 = tslib_1.__importDefault(require("../../classes/distro"));
// libraries
const chalk_1 = tslib_1.__importDefault(require("chalk"));
/**
 *
 */
class List extends core_1.Command {
    async run() {
        const { args, flags } = await this.parse(List);
        let verbose = false;
        if (flags.verbose) {
            verbose = true;
        }
        const echo = utils_1.default.setEcho(verbose);
        utils_1.default.titles(this.id + ' ' + this.argv);
        /**
        * wardobe
        */
        let wardrobe = await utils_1.default.wardrobe();
        if (flags.distro === undefined) {
            if (this.argv['0'] !== undefined) {
                wardrobe = this.argv['0'];
            }
        }
        /**
         * seleziona distro
         */
        let index = '';
        let distro = new distro_1.default();
        if (distro.distroLike === "Arch") {
            index = 'arch';
        }
        else if (distro.distroLike === "Debian" || distro.distroLike === "Devuan") {
            index = 'debian';
        }
        else if (distro.distroLike === "Ubuntu") {
            index = 'ubuntu';
        }
        if (flags.distro !== undefined) {
            index = flags.distro;
        }
        index += '.yml';
        console.log(chalk_1.default.green('wardrobe: ') + wardrobe);
        console.log();
        wardrobe = `${path_1.default.resolve(process.cwd(), wardrobe)}/`;
        if (!fs_1.default.existsSync(wardrobe)) {
            utils_1.default.warning(`wardrobe: ${wardrobe} not found!`);
            process.exit();
        }
        /**
        * costumes
        */
        const costumes = fs_1.default.readdirSync(`${wardrobe}costumes/`);
        console.log(chalk_1.default.green('costumes: '));
        for (const costume of costumes) {
            if (fs_1.default.existsSync(`${wardrobe}costumes/${costume}/${index}`)) {
                const materials = js_yaml_1.default.load(fs_1.default.readFileSync(`${wardrobe}costumes/${costume}/${index}`, 'utf-8'));
                console.log('- ' + chalk_1.default.cyan(costume) + ': ' + materials.description);
            }
        }
        console.log();
        /**
         * accessories
         */
        const accessories = fs_1.default.readdirSync(`${wardrobe}/accessories/`);
        console.log(chalk_1.default.green('accessories: '));
        for (const accessory of accessories) {
            if (fs_1.default.existsSync(`${wardrobe}/accessories/${accessory}/${index}`)) {
                const materials = js_yaml_1.default.load(fs_1.default.readFileSync(`${wardrobe}/accessories/${accessory}/${index}`, 'utf-8'));
                console.log('- ' + chalk_1.default.cyan(accessory) + ': ' + materials.description);
            }
        }
        console.log();
        /**
         * servers
         */
        const servers = fs_1.default.readdirSync(`${wardrobe}/servers/`);
        console.log(chalk_1.default.green('servers: '));
        for (const server of servers) {
            if (fs_1.default.existsSync(`${wardrobe}/servers/${server}/${index}`)) {
                const materials = js_yaml_1.default.load(fs_1.default.readFileSync(`${wardrobe}/servers/${server}/${index}`, 'utf-8'));
                console.log('- ' + chalk_1.default.cyan(server) + ': ' + materials.description);
            }
        }
        console.log();
        /**
         * vendors
         */
        const vendors = fs_1.default.readdirSync(`${wardrobe}/vendors/`);
        console.log(chalk_1.default.green('vendors/themes: '));
        for (const vendor of vendors) {
            if (fs_1.default.existsSync(`${wardrobe}/vendors/${vendor}/theme`)) {
                console.log('- ' + chalk_1.default.cyan(vendor));
            }
        }
        console.log();
    }
}
List.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    distro: core_1.Flags.string({ char: 'd', description: 'distro' }),
    verbose: core_1.Flags.boolean({ char: 'v' }),
};
List.args = [{ name: 'wardrobe', description: 'wardrobe', required: false }];
List.description = 'list costumes and accessoires in wardrobe';
List.examples = [
    'eggs wardrobe list',
    'eggs wardrobe list your-wardrobe',
    'eggs wardrobe list --distro arch',
];
exports.default = List;
