"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("@refloat/logger");
const commander_1 = require("commander");
require("./suppress-warnings");
const agents_1 = require("./agents/agents");
const config_1 = require("./config");
const workspace_1 = require("./cli/workspace");
const banner_1 = (0, tslib_1.__importDefault)(require("./banner"));
function run({ argv = process.argv, exitOnError = true } = {}) {
    program.parseAsync(argv).catch((error) => {
        if (exitOnError) {
            logger.error('fatal error', { error });
            process.exit(2);
        }
    });
}
exports.run = run;
const program = new commander_1.Command('refloat-agent');
const logger = logger_1.Logger.create('cli');
program
    .version('0.0.1', '-v, --version')
    .description('start an agent')
    .option('-t, --token <token>', 'setup the agent token (defaults to REFLOAT_TOKEN)', process.env.REFLOAT_TOKEN)
    .option('-d, --debug', 'enable debug logs (enabled if REFLOAT_DEBUG is `true`)')
    .action(async function run(options) {
    const config = config_1.Configuration.set({
        api: options.api ? new URL(options.api) : undefined,
        token: options.token,
        debug: options.debug,
    });
    console.log(banner_1.default);
    logger.debug('starting program', { config });
    await (0, agents_1.agents)();
});
const commands = {
    import: program.command('import'),
    export: program.command('export'),
};
commands.export
    .command('workspace <build-id> <name> <files...>')
    .action(async (buildId, name, files) => (0, workspace_1.exportWorkspace)(files, { buildId, name }));
commands.export
    .command('artifact <step-id> <files...>')
    .option('-n, --name <name>', 'set the artifact name (defaults to the file name)')
    .action(async (stepId, files, { name }) => (0, workspace_1.exportArtifact)(files, { stepId, name }));
commands.import
    .command('workspace <build-id> <name>')
    .action(async (buildId, name) => (0, workspace_1.importWorkspace)({ buildId, name }));
commands.import
    .command('artifact <build-id> <file>')
    .action(async (buildId, file) => (0, workspace_1.importArtifact)(file, { buildId }));
//# sourceMappingURL=cli.js.map