import { captureEvent } from "./lib.js";
const CLI_COMMAND_ALIASES = new Map([
    ["oas", "openapi"],
    ["open-api", "openapi"],
]);
let hasCapturedCliInvocation = false;
function getCommandToken(argv) {
    if (!argv || typeof argv !== "object") {
        return undefined;
    }
    const tokens = argv._;
    const command = tokens?.[0];
    if (typeof command !== "string") {
        return undefined;
    }
    return CLI_COMMAND_ALIASES.get(command) ?? command;
}
export function getCliInvocationProperties(argv, version) {
    return {
        version,
        cliCommand: getCommandToken(argv) ?? "unknown",
    };
}
export async function captureCliInvocationEvent(argv, version, capture = captureEvent) {
    if (hasCapturedCliInvocation) {
        return;
    }
    hasCapturedCliInvocation = true;
    try {
        await capture({
            argv,
            event: "zuplo cli invoked",
            properties: getCliInvocationProperties(argv, version),
        });
    }
    catch {
    }
}
//# sourceMappingURL=cli-invocation.js.map