"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * command: skel.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 fs_1 = tslib_1.__importDefault(require("fs"));
const xdg_1 = tslib_1.__importDefault(require("../../classes/xdg"));
class Skel extends core_1.Command {
    async run() {
        utils_1.default.titles(this.id + ' ' + this.argv);
        const { flags } = await this.parse(Skel);
        let verbose = false;
        if (flags.verbose) {
            verbose = true;
        }
        let user = '';
        user = flags.user ? flags.user : await utils_1.default.getPrimaryUser();
        utils_1.default.warning(`user: ${user}`);
        const homeSource = `/home/${user}`;
        if (!fs_1.default.existsSync(homeSource)) {
            utils_1.default.error(`User ${user} not exist or not exist a proper home`);
            utils_1.default.warning('terminate');
            process.exit(0);
        }
        if (utils_1.default.isRoot()) {
            utils_1.default.titles('skel');
            xdg_1.default.skel(user, verbose);
        }
        else {
            utils_1.default.useRoot(this.id);
        }
    }
}
Skel.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    user: core_1.Flags.string({ char: 'u', description: 'user to be used' }),
    verbose: core_1.Flags.boolean({ char: 'v' }),
};
Skel.description = 'update skel from home configuration';
Skel.examples = [
    'sudo eggs tools skel',
    'sudo eggs tools skel --user user-to-be-copied',
];
exports.default = Skel;
