"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _commander() {
    const data = require("commander");
    _commander = function() {
        return data;
    };
    return data;
}
const _compiler = /*#__PURE__*/ _interop_require_wildcard(require("./compiler"));
function _packagejson() {
    const data = require("~/package.json");
    _packagejson = function() {
        return data;
    };
    return data;
}
const _exceptions = require("./exceptions");
const _user = /*#__PURE__*/ _interop_require_wildcard(require("./user"));
const _project = /*#__PURE__*/ _interop_require_wildcard(require("./project"));
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const main = async ()=>{
    (0, _exceptions.handleExceptions)();
    const program = new (_commander()).Command();
    program.option("-v, --version", "Show version").option("--skip-remote", "Skip remote checks", false).action(async ({ skipRemote })=>{
        let data = {
            qpace: _packagejson().version,
            qpaceCore: _packagejson().coreVersion
        };
        if (!skipRemote) {
            try {
                const [compilerClient] = await _compiler.getCompilerClient();
                const compilerInfo = await _compiler.fetchInfo(compilerClient);
                data = {
                    ...data,
                    compiler: compilerInfo.version,
                    compilerDate: compilerInfo.buildDate.toLocaleString()
                };
            } catch (e) {
                console.log(e);
            }
        }
        console.table(data);
    });
    _user.getCommands().forEach((r)=>program.addCommand(r));
    _project.getCommands().forEach((r)=>program.addCommand(r));
    _compiler.getCommands().forEach((r)=>program.addCommand(r));
    program.parse();
};
main();
