"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * command: kill.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 settings_1 = tslib_1.__importDefault(require("../classes/settings"));
const kill_me_softly_1 = tslib_1.__importDefault(require("../lib/kill_me_softly"));
/**
 *
 */
class Kill extends core_1.Command {
    constructor() {
        super(...arguments);
        this.config_file = '/etc/penguins-eggs.d/eggs.yaml';
        this.snapshot_dir = '';
    }
    async run() {
        utils_1.default.titles(this.id + ' ' + this.argv);
        const { flags } = await this.parse(Kill);
        const verbose = flags.verbose;
        const isos = flags.isos;
        const nointeractive = flags.nointeractive;
        const echo = utils_1.default.setEcho(verbose);
        if (utils_1.default.isRoot()) {
            const settings = new settings_1.default();
            await settings.load();
            await settings.listFreeSpace();
            if (utils_1.default.isMountpoint(settings.config.snapshot_mnt)) {
                console.log('==========================================');
                utils_1.default.warning('You are working on a mountpoint');
                console.log('==========================================');
            }
            if (nointeractive || await utils_1.default.customConfirm()) {
                await (0, kill_me_softly_1.default)(settings.config.snapshot_dir, settings.config.snapshot_mnt, isos);
            }
        }
        else {
            utils_1.default.useRoot(this.id);
        }
    }
}
Kill.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    nointeractive: core_1.Flags.boolean({ char: 'n', description: 'no user interaction' }),
    isos: core_1.Flags.boolean({ char: 'i', description: 'erase all ISOs on remote mount' }),
    verbose: core_1.Flags.boolean({ char: 'v', description: 'verbose' }),
};
Kill.description = 'kill the eggs/free the nest';
Kill.examples = [
    'sudo eggs kill',
];
exports.default = Kill;
