56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
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 (
|
|
flagVersion bool
|
|
flagList bool
|
|
flagIncludeAll bool
|
|
flagExcludeAll bool
|
|
flagExcept arrayFlags
|
|
)
|
|
|
|
func init() {
|
|
flag.BoolVar(&flagList, "list", false, "Only list database names.")
|
|
flag.BoolVar(&flagVersion, "version", false, "Prints version and exits.")
|
|
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()
|
|
|
|
if flagVersion {
|
|
fmt.Println(VERSION)
|
|
os.Exit(0)
|
|
}
|
|
|
|
if flagList && (flagIncludeAll || flagExcludeAll || len(flagExcept) > 0) {
|
|
fmt.Println("-list is not usable with any other flag.")
|
|
os.Exit(1)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|