"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupCLICommonParams = void 0;
const findUp = require("find-up");
const fs = require("fs");
const utils_1 = require("./utils");
const configPath = findUp.sync(['.syftrc', '.syftrc.json']);
let config = {};
if (configPath !== undefined && configPath !== null) {
    try {
        config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
    }
    catch (e) {
        (0, utils_1.logError)(`:warning: Invalid config file ${configPath}. Using default values`);
    }
}
const handleVerbosity = ({ verbose }) => {
    (0, utils_1.toggleVerbosity)(verbose);
};
function setupCLICommonParams(cli) {
    return cli
        .option('remote', {
        describe: 'Remote Server Base Url',
        type: 'string',
        default: 'https://studio.syftdata.com',
        hidden: true
    })
        .option('force', {
        describe: 'Force an operation without exiting early.',
        type: 'boolean',
        default: false,
        hidden: true
    })
        .option('verbose', {
        describe: 'Enable verbose mode',
        default: false,
        type: 'boolean'
    })
        .middleware(handleVerbosity)
        .config(config)
        .pkgConf('syft')
        .fail((msg, e) => {
        (0, utils_1.logUnknownError)(msg, e);
        process.exit(1);
    });
}
exports.setupCLICommonParams = setupCLICommonParams;
