import { Command } from "@cliffy/command"; import { type ColorWhen, ViewError, viewMain } from "../lib/view/mod.ts"; import { cliText } from "../lib/cli-name.ts"; import { languageNames } from "../lib/view/languages/language.ts"; const description = cliText( `Interactive, syntax-aware pager for transformed patterns, source files and diffs. A less-like viewer for the dense output of '--show-transformed' and saved source files. Transformed TypeScript is parsed with the same parser the transformer uses, so blocks, closures, schemas, type positions and Common Fabric builders (pattern/lift/handler/…) are colored exactly as the compiler sees them. Markdown, JSON, JSONC, YAML, Python, Swift, Kotlin, TOML, HCL, shell, makefile, Java properties, INI, ProGuard and XML files use syntax highlighting selected from language metadata. Kotlin covers Gradle's '.gradle.kts' build scripts, HCL covers OpenTofu and Terraform configuration, shell covers Bash and POSIX shell, makefiles color their recipes as shell, INI covers Ansible configuration and inventories, and XML covers Android manifests and resources, SVG and Apple property lists. Python interpreter shebangs select Python, 'swift' and 'xcrun swift' shebangs select Swift, 'kotlin' shebangs select Kotlin, 'sh', 'bash', 'dash' and 'ash' shebangs select shell, and 'make' and 'gmake' shebangs select the makefile language. Node, Deno and Bun shebangs select the TypeScript and JavaScript language family. For a name no language claims, source that starts with an XML declaration ('", "Colorize: always | auto | never (auto = when stdout is a TTY).", { default: "auto" }, ) .option( "--plain", "Do not launch the interactive pager; print colorized text and exit.", ) .option( "-n, --line-numbers", "Show line numbers (toggle with # in the viewer).", ) .option( "--rendered", "Start in the rendered view when the input language supports one.", ) .option( "--language ", `Select piped source explicitly: ${languageNames().join(", ")}.`, ) .option( "--filename ", "Select piped source as though it had this filename.", ) .option( "--diff", "Treat the input as a unified diff, overriding auto-detection.", ) .option( "--no-diff", "Treat the input as source even if it looks like a diff.", ) .arguments("[file:string]") .action( async ( options: { color?: string; plain?: boolean; lineNumbers?: boolean; rendered?: boolean; language?: string; filename?: string; diff?: boolean; }, file?: string, ) => { try { const when = (options.color ?? "auto") as ColorWhen; if (when !== "always" && when !== "auto" && when !== "never") { throw new ViewError( `--color must be always, auto, or never (got "${when}")`, ); } await viewMain({ color: when, plain: options.plain ?? false, lineNumbers: options.lineNumbers ?? false, rendered: options.rendered ?? false, language: options.language, filename: options.filename, file, diff: options.diff, }); } catch (error) { // Expected, user-facing conditions print plainly without a stack trace. if (error instanceof ViewError) { console.error(error.message); Deno.exit(1); } throw error; } }, );