"use strict";
/*
 * Copyright 2020 NEM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const service_1 = require("../service");
const CommandUtils_1 = require("../service/CommandUtils");
class Config extends command_1.Command {
    async run() {
        const { flags } = this.parse(Config);
        service_1.BootstrapUtils.showBanner();
        flags.password = await CommandUtils_1.CommandUtils.resolvePassword(flags.password, flags.noPassword, CommandUtils_1.CommandUtils.passwordPromptDefaultMessage, true);
        await new service_1.BootstrapService(this.config.root).config(flags);
    }
}
exports.default = Config;
Config.description = 'Command used to set up the configuration files and the nemesis block for the current network';
Config.examples = [
    `$ symbol-bootstrap config -p bootstrap`,
    `$ symbol-bootstrap config -p testnet -a dual --password 1234`,
    `$ echo "$MY_ENV_VAR_PASSWORD" | symbol-bootstrap config -p testnet -a dual`,
];
Config.flags = {
    help: CommandUtils_1.CommandUtils.helpFlag,
    target: CommandUtils_1.CommandUtils.targetFlag,
    password: CommandUtils_1.CommandUtils.passwordFlag,
    noPassword: CommandUtils_1.CommandUtils.noPasswordFlag,
    preset: command_1.flags.enum({
        char: 'p',
        description: 'The network preset, can be provided via custom preset or cli parameter. If not provided, the value is resolved from the target/preset.yml file.',
        options: Object.keys(service_1.Preset).map((v) => v),
    }),
    assembly: command_1.flags.string({
        char: 'a',
        description: 'The assembly, example "dual" for testnet. If not provided, the value is resolved from the target/preset.yml file.',
    }),
    customPreset: command_1.flags.string({
        char: 'c',
        description: 'External preset file. Values in this file will override the provided presets (optional)',
        required: false,
    }),
    reset: command_1.flags.boolean({
        char: 'r',
        description: 'It resets the configuration generating a new one',
        default: service_1.ConfigService.defaultParams.reset,
    }),
    upgrade: command_1.flags.boolean({
        description: `It regenerates the configuration reusing the previous keys. Use this flag when upgrading the version of bootstrap to keep your node up to date without dropping the local data. The original preset (-t), assembly (-a), and custom preset (-a) must be used. Backup the target folder before upgrading.`,
        default: service_1.ConfigService.defaultParams.reset,
    }),
    report: command_1.flags.boolean({
        description: 'It generates reStructuredText (.rst) reports describing the configuration of each node.',
        default: service_1.ConfigService.defaultParams.report,
    }),
    pullImages: command_1.flags.boolean({
        description: 'It pulls the utility images from DockerHub when running the configuration. It only affects alpha/dev docker images.',
        default: service_1.ConfigService.defaultParams.pullImages,
    }),
    user: command_1.flags.string({
        char: 'u',
        description: `User used to run docker images when creating configuration files like certificates or nemesis block. "${service_1.BootstrapUtils.CURRENT_USER}" means the current user.`,
        default: service_1.BootstrapUtils.CURRENT_USER,
    }),
};
