forked from go/pgm
51 lines
928 B
Go
51 lines
928 B
Go
// Patial Tech.
|
|
// Author, Ankit Patial
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var (
|
|
showVersion bool
|
|
)
|
|
|
|
const usageTxt = `Please provide output directory and input schema.
|
|
Example:
|
|
pgm -o ./db ./schema.sql
|
|
|
|
`
|
|
|
|
func main() {
|
|
var outDir string
|
|
flag.StringVar(&outDir, "o", "", "-o as output directory path")
|
|
flag.BoolVar(&showVersion, "version", false, "show version information")
|
|
flag.Parse()
|
|
|
|
// Handle version flag
|
|
if showVersion {
|
|
fmt.Printf("pgm %s\n", GetVersionString())
|
|
fmt.Println("PostgreSQL Query Mapper - Schema code generator")
|
|
fmt.Println("https://code.patial.tech/go/pgm")
|
|
return
|
|
}
|
|
if len(os.Args) < 4 {
|
|
fmt.Print(usageTxt)
|
|
return
|
|
}
|
|
|
|
if outDir == "" {
|
|
fmt.Fprintln(os.Stderr, "Error: missing output directory path (-o flag required)")
|
|
os.Exit(1)
|
|
return
|
|
}
|
|
|
|
if err := generate(os.Args[3], outDir); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|