"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const minimist_1 = __importDefault(require("minimist"));
const getFile_1 = require("./getFile");
const getGitRootDir_1 = __importDefault(require("./getGitRootDir"));
let root;
try {
    root = (0, getGitRootDir_1.default)();
}
catch (error) {
    throw new Error('Could not find Git root folder');
}
const pkg = (0, getFile_1.getPackage)(root);
const helpScreen = `
    > ${pkg.name}
    > ${pkg.version}
    > ${pkg.description}

    Usage: git-cz [options]

    options:
        -h, --help          show usage information
        -v, --version       print version info and exit
        -m, --mode          commit|branch (default: commit)
        --dry-run           dry run of mode for testing purposes
        --format            format based of of --mode
        --non-interactive   run git-cz in non-interactive mode

    non-interactive mode options:
        --commitBody        extended description of the commit
        --commitBreaking    description of breaking changes, if any
        --commitScopes      semantic commit scope
        --commitSubject     message of the commit (default: automated commit)
        --commitTypes       type of the commit (default: chore)
`;
const parseArgs = () => {
    const _a = (0, minimist_1.default)(process.argv.slice(2), {
        alias: {
            h: 'help',
            m: 'mode',
            v: 'version',
        },
        boolean: ['dry-run', 'help', 'hook', 'non-interactive', 'version'],
        string: [
            'commitBody',
            'commitBreaking',
            'commitScope',
            'commitSubject',
            'commitTypes',
            'format',
            'mode',
        ],
    }), { _: inputs, 'dry-run': dryRun, 'non-interactive': nonInteractive, commitBody, commitBreaking, commitScope, commitSubject, commitTypes, format, h, help, hook, m, mode, v, version } = _a, passThroughParams = __rest(_a, ["_", 'dry-run', 'non-interactive', "commitBody", "commitBreaking", "commitScope", "commitSubject", "commitTypes", "format", "h", "help", "hook", "m", "mode", "v", "version"]);
    if (help || h) {
        console.log(helpScreen);
        process.exit();
    }
    if (version || v) {
        console.log(pkg.version);
        process.exit();
    }
    if (mode === 'branch' || m === 'branch') {
        passThroughParams.verify = false;
        passThroughParams['allow-empty'] = true;
    }
    let commitBreakingFlag = false;
    if (commitBreaking) {
        commitBreakingFlag = true;
    }
    const cliOptions = {
        dryRun,
        format,
        help,
        hook,
        mode: mode || 'commit',
        nonInteractive,
        version,
    };
    const cliAnswers = {
        commitBody,
        commitBreaking,
        commitBreakingFlag,
        commitScope,
        commitSubject,
        commitTypes,
        mode: mode || 'commit',
    };
    return {
        cliAnswers,
        cliOptions,
        passThroughParams,
    };
};
exports.default = parseArgs;
//# sourceMappingURL=parseArgs.js.map