import { captureEvent } from "../../common/analytics/lib.js";
import { authenticateNoPrompt } from "../../common/middleware/authentication.js";
import { identify } from "../../common/middleware/user-identification.js";
import { readLinkedConfig } from "../../common/read-linked-config.js";
import { info } from "../../project/info/handler.js";
async function authenticateIfLinked(argv) {
    const linked = await readLinkedConfig(argv);
    if (linked.accountName && linked.projectName) {
        argv.account = linked.accountName;
        argv.project = linked.projectName;
        await authenticateNoPrompt(argv);
    }
}
export function configureInfoOptions(yargs) {
    return yargs
        .option("api-key", {
        type: "string",
        describe: "The API Key from Zuplo",
        envVar: "API_KEY",
        alias: "apikey",
    })
        .option("dir", {
        type: "string",
        describe: "The directory containing your Zuplo API",
        default: ".",
        normalize: true,
        hidden: true,
    })
        .middleware([authenticateIfLinked, identify]);
}
export default {
    desc: "Displays information about the current project and linked environment",
    command: "info",
    builder: (yargs) => {
        return configureInfoOptions(yargs)
            .usage("$0 project info [options]")
            .example([
            [
                "$0 project info",
                "Display information about the current linked project",
            ],
        ]);
    },
    handler: async (argv) => {
        await captureEvent({ argv, event: "zuplo project info" });
        await info(argv);
    },
};
//# sourceMappingURL=info.js.map