"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_pipe_1 = __importDefault(require("chalk-pipe"));
const isEnabled_1 = __importDefault(require("./utils/isEnabled"));
const parseArgs_1 = __importDefault(require("./utils/parseArgs"));
const runInteractiveQuestions_1 = __importDefault(require("./utils/runInteractiveQuestions"));
const runNonInteractiveMode_1 = __importDefault(require("./utils/runNonInteractiveMode"));
const setBranch_1 = __importDefault(require("./utils/setBranch"));
const setCommit_1 = __importDefault(require("./utils/setCommit"));
const setState_1 = __importDefault(require("./utils/setState"));
const cli = () => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const { cliAnswers, cliOptions, passThroughParams } = (0, parseArgs_1.default)();
        const state = (0, setState_1.default)(cliOptions);
        yield (0, isEnabled_1.default)(state);
        Object.keys(cliAnswers).forEach((key) => {
            state.answers[key] = cliAnswers[key];
        });
        const appendedArgs = [];
        for (const key in passThroughParams) {
            const value = passThroughParams[key];
            if (key.length === 1) {
                appendedArgs.push('-' + key);
            }
            else {
                appendedArgs.push('--' + key);
            }
            if (value !== true) {
                appendedArgs.push(value);
            }
        }
        if (cliOptions.nonInteractive) {
            (0, runNonInteractiveMode_1.default)(state, cliAnswers);
        }
        else {
            yield (0, runInteractiveQuestions_1.default)(state, cliAnswers, cliOptions);
        }
        const options = {
            appendedArgs,
            cliAnswers,
            cliOptions,
            passThroughParams,
            state,
        };
        switch (cliOptions.mode) {
            case 'branch':
                (0, setBranch_1.default)(options);
                break;
            case 'commit':
            default:
                (0, setCommit_1.default)(options);
                break;
        }
    }
    catch (error) {
        console.log((0, chalk_pipe_1.default)('red.bold')('⚠️ error:'));
        console.log((0, chalk_pipe_1.default)('white.italic')(`${error}`));
    }
});
cli();
//# sourceMappingURL=cli.js.map