#!/usr/bin/env -S deno run --allow-all import { parseArgs } from "@std/cli/parse-args"; import { logger } from "./utils/logger.ts"; import { loginCommand } from "./commands/login.ts"; import { lexiconCommand } from "./commands/lexicon.ts"; import { statusCommand } from "./commands/status.ts"; import { codegenCommand } from "./commands/codegen.ts"; import { initCommand } from "./commands/init.ts"; import { logsCommand } from "./commands/logs.ts"; const VERSION = "0.1.0"; function showHelp() { console.log(` Slices CLI v${VERSION} - AT Protocol Slice Management Tool USAGE: slices [OPTIONS] COMMANDS: init Initialize a new Deno SSR project with OAuth login Authenticate with Slices using device code flow lexicon Manage lexicons (push, pull, list) codegen Generate TypeScript client from lexicon files status Show authentication and configuration status logs View Jetstream logs for a slice help Show this help message OPTIONS: -h, --help Show help information -v, --verbose Enable verbose logging --version Show version information EXAMPLES: slices init my-app slices login slices lexicon push --path ./lexicons --slice at://did:plc:example/slice slices lexicon list --slice at://did:plc:example/slice slices status slices logs --slice at://did:plc:example/slice `); } function showVersion() { console.log(`slices v${VERSION}`); } if (import.meta.main) { const args = parseArgs(Deno.args, { boolean: ["help", "verbose", "version"], string: [], alias: { h: "help", v: "verbose", }, stopEarly: true, // Stop parsing at first non-option argument (the command) }); if (args.verbose) { logger.setVerbose(true); } if (args.version) { showVersion(); Deno.exit(0); } if (args.help || args._.length === 0) { showHelp(); Deno.exit(0); } const command = args._[0] as string; const commandIndex = Deno.args.findIndex((arg) => arg === command); const commandArgs = Deno.args.slice(commandIndex + 1); try { switch (command) { case "init": await initCommand(commandArgs, args); break; case "login": await loginCommand(commandArgs, args); break; case "lexicon": await lexiconCommand(commandArgs, args); break; case "codegen": await codegenCommand(commandArgs, args); break; case "status": await statusCommand(commandArgs, args); break; case "logs": await logsCommand(commandArgs, args); break; case "help": showHelp(); break; default: console.error(`Unknown command: ${command}`); console.error("Run 'slices help' for usage information."); Deno.exit(1); } } catch (error) { const err = error as Error; logger.error("Command failed:", err.message); if (args.verbose) { logger.error("Stack trace:", err.stack); } Deno.exit(1); } }