/**
 * Ghostflow CLI Entry Point
 *
 * Main entry for the ghostflow command-line interface.
 * Built with @effect/cli for type-safe argument parsing and help generation.
 *
 * When run without arguments, launches the interactive TUI dashboard.
 * Otherwise, runs the specified subcommand.
 */
import { Command } from "@effect/cli";
import { NodeRuntime } from "@effect/platform-node";
import { Array as Arr, Effect, Option as O } from "effect";
import { addCommand, listCommand, migrateCommand, removeCommand, restartCommand, startCommand, statusCommand, stopCommand, syncCommand } from "./commands/index.js";
import { MainLive } from "./layers/index.js";
import { tui } from "./tui/index.js";
// ============================================================================
// CLI Definition
// ============================================================================
const cli = Command.make("ghostflow").pipe(Command.withDescription("Ghostflow - Automatic Git Synchronization"), Command.withSubcommands([
    statusCommand,
    startCommand,
    stopCommand,
    restartCommand,
    syncCommand,
    listCommand,
    addCommand,
    removeCommand,
    migrateCommand
]));
const runCli = Command.run(cli, {
    name: "ghostflow",
    version: "0.1.0"
});
// ============================================================================
// Constants
// ============================================================================
/** Number of leading argv elements to skip (node, script path) */
const ARGV_SKIP_COUNT = 2;
/** Flag prefix for command line options */
const FLAG_PREFIX = "-";
// ============================================================================
// Helpers
// ============================================================================
/** Predicate: string is a CLI flag (starts with "-") */
const isFlag = (arg) => arg.startsWith(FLAG_PREFIX);
/** Predicate: string is a subcommand (not a flag) */
const isNonFlagArgument = (arg) => !isFlag(arg);
/** Check if first argument is a subcommand */
const isSubcommand = (firstArg) => O.match(firstArg, {
    onNone: () => false,
    onSome: isNonFlagArgument
});
// ============================================================================
// Entry Point
// ============================================================================
/**
 * Check if user provided any subcommand arguments.
 * argv[0] = node, argv[1] = script path, argv[2+] = arguments
 * Uses Effect Array utilities for safe access.
 *
 * @param argv - Command line arguments (defaults to process.argv for production)
 */
const hasSubcommand = (argv = process.argv) => Arr.match(Arr.drop(argv, ARGV_SKIP_COUNT), {
    onEmpty: () => false,
    onNonEmpty: (nonEmpty) => isSubcommand(Arr.head(nonEmpty))
});
// Select and run the appropriate program
const program = hasSubcommand()
    ? runCli(process.argv)
    : tui();
NodeRuntime.runMain(program.pipe(Effect.provide(MainLive)));
//# sourceMappingURL=main.js.map