7fb76bae3d
* Implement migration safety rules: - MIG001: Warn on CREATE INDEX without CONCURRENT. - MIG002: Warn on ALTER TABLE ADD COLUMN NOT NULL without DEFAULT. - MIG003: Warn on ALTER TABLE ADD CONSTRAINT without NOT VALID. * Implement naming conventions rules: - NAM001: Warn on non-snake_case table names. - NAM002: Warn on non-snake_case column names in CREATE TABLE. - NAM003: Warn on non-snake_case function names. * Add test fixtures for all new rules.
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// 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 "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 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.
|
|
`)
|
|
}
|