go/sqlgen/main.go
2024-11-19 16:30:42 +01:00

48 lines
688 B
Go

package sqlgen
import (
"fmt"
"os"
)
const (
DRIVER_SQLITE = "sqlite"
DRIVER_POSTGRES = "postgres"
)
func Main() {
usage := func() {
fmt.Fprintf(os.Stderr, `
%s DRIVER DEFS_PATH OUTPUT_PATH
Drivers are one of: %s %s
`,
os.Args[0], DRIVER_SQLITE, DRIVER_POSTGRES)
os.Exit(1)
}
if len(os.Args) != 4 {
usage()
}
var (
driver = os.Args[1]
defsPath = os.Args[2]
outputPath = os.Args[3]
)
switch driver {
case DRIVER_SQLITE, DRIVER_POSTGRES:
// OK
default:
fmt.Fprintf(os.Stderr, "Unknown driver: %s", driver)
usage()
}
err := render(driver, defsPath, outputPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v", err)
os.Exit(1)
}
}