go/sqlgen/main.go

48 lines
688 B
Go
Raw Normal View History

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