// Command pgtidy is the PgTidy CLI: a PostgreSQL formatter and linter. package main import ( "fmt" "io" "os" ) // version is overridden at build time via -ldflags "-X main.version=...". var version = "dev" func main() { os.Exit(run(os.Args[1:], os.Stdin, os.Stdout, os.Stderr)) } func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int { if len(args) == 0 { usage(stderr) return 2 } switch args[0] { case "fmt", "format": return cmdFmt(args[1:], stdin, stdout, stderr) case "lint": return cmdLint(args[1:], stdin, stdout, stderr) case "lsp": return cmdLsp(args[1:], stdin, stdout, stderr) case "config": return cmdConfig(args[1:], stdin, stdout, stderr) case "version", "--version", "-v": fmt.Fprintf(stdout, "pgtidy %s\n", version) return 0 case "help", "-h", "--help": usage(stdout) return 0 default: fmt.Fprintf(stderr, "pgtidy: unknown command %q\n", args[0]) usage(stderr) return 2 } } func usage(w io.Writer) { fmt.Fprint(w, `pgtidy — PostgreSQL formatter and linter Usage: pgtidy fmt [flags] [files...] Format SQL/PL-pgSQL (stdin if no files) pgtidy lint [flags] [files...] Lint SQL (stdin if no files) pgtidy config Print effective configuration pgtidy lsp Start LSP server (stdio, for editors) pgtidy version Print version pgtidy help Show this help fmt flags: -w, --write Rewrite files in place -l, --list List files whose formatting differs (no writes) -d, --diff Print unified diff of changes --check Exit non-zero if any input is not already formatted (CI) lint flags: --only=ID,... Enable only the specified rule IDs (comma-separated) Run 'pgtidy lint --help' for the full rule list. `) }