2024-04-23 20:17:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
// Stnadard
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type arrayFlags []string
|
|
|
|
|
|
|
|
func (i *arrayFlags) String() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *arrayFlags) Set(value string) error {
|
|
|
|
*i = append(*i, value)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2024-04-23 20:21:08 +02:00
|
|
|
flagVersion bool
|
2024-04-23 20:17:43 +02:00
|
|
|
flagIncludeAll bool
|
|
|
|
flagExcludeAll bool
|
|
|
|
flagExcept arrayFlags
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-04-23 20:21:08 +02:00
|
|
|
flag.BoolVar(&flagVersion, "version", false, "Prints version and exits.")
|
2024-04-23 20:17:43 +02:00
|
|
|
flag.BoolVar(&flagIncludeAll, "include-all", false, "Split out all databases, with provided exceptions.")
|
|
|
|
flag.BoolVar(&flagExcludeAll, "exclude-all", false, "Split out no databases, with provided exceptions.")
|
|
|
|
flag.Var(&flagExcept, "except", "Exception to rule, can be used multiple times")
|
|
|
|
flag.Parse()
|
|
|
|
|
2024-04-23 20:21:08 +02:00
|
|
|
if flagVersion {
|
|
|
|
fmt.Println(VERSION)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-04-23 20:17:43 +02:00
|
|
|
if flagIncludeAll && flagExcludeAll {
|
|
|
|
fmt.Println("-include-all and -exclude-all are mutually exclusive")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if flagExcludeAll && len(flagExcept) == 0 {
|
|
|
|
fmt.Println("All databases are excluded and pgsplit is pointless.")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|