#!/usr/bin/env node
import * as Command from "@effect/cli/Command";
import * as Options from "@effect/cli/Options";
import * as ValidationError from "@effect/cli/ValidationError";
import * as NodeContext from "@effect/platform-node/NodeContext";
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as PlatformConfigProvider from "@effect/platform/PlatformConfigProvider";
import * as Cause from "effect/Cause";
import * as Config from "effect/Config";
import * as Console from "effect/Console";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Logger from "effect/Logger";
import * as LogLevel from "effect/LogLevel";
import * as String from "effect/String";
import * as Utils from "../Utils.js";
import { auth } from "./commands/auth/index.js";
import { build } from "./commands/build.js";
import { deploy } from "./commands/deploy.js";
import { dev } from "./commands/dev.js";
import { proxy } from "./commands/proxy.js";
import { publish } from "./commands/publish.js";
import { query } from "./commands/query.js";
import { register } from "./commands/register.js";
import { studio } from "./commands/studio.js";
import pkg from "../../package.json" with { type: "json" };
const levels = LogLevel.allLevels.map((value) => String.toLowerCase(value.label));
const amp = Command.make("amp", {
    args: {
        logs: Options.choice("logs", levels).pipe(Options.withFallbackConfig(Config.string("AMP_LOG_LEVEL").pipe(Config.withDefault("info"))), Options.withDescription("The log level to use"), Options.map((value) => LogLevel.fromLiteral(String.capitalize(value)))),
    },
}).pipe(Command.withDescription("The Amp Command Line Interface"), Command.withSubcommands([build, dev, deploy, query, proxy, register, publish, studio, auth]), Command.provide(({ args }) => Logger.minimumLogLevel(args.logs)));
const cli = Command.run(amp, {
    name: "Amp",
    version: `v${pkg.version}`,
});
const layer = Layer.provideMerge(PlatformConfigProvider.layerDotEnvAdd(".env"), NodeContext.layer);
const runnable = Effect.suspend(() => cli(process.argv)).pipe(Effect.provide(layer), Effect.tapErrorCause((cause) => {
    const squashed = Cause.squash(cause);
    // Command validation errors are already printed by @effect/cli.
    if (ValidationError.isValidationError(squashed)) {
        return Effect.void;
    }
    return Console.error(Utils.prettyCause(cause));
}));
runnable.pipe(NodeRuntime.runMain({ disableErrorReporting: true }));
//# sourceMappingURL=main.js.map