pgsplit/flag.go

57 lines
1.3 KiB
Go
Raw Permalink Normal View History

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:24:40 +02:00
flagList bool
2024-04-23 20:17:43 +02:00
flagIncludeAll bool
flagExcludeAll bool
flagExcept arrayFlags
)
func init() {
2024-04-23 20:24:40 +02:00
flag.BoolVar(&flagList, "list", false, "Only list database names.")
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:24:40 +02:00
if flagList && (flagIncludeAll || flagExcludeAll || len(flagExcept) > 0) {
fmt.Println("-list is not usable with any other flag.")
os.Exit(1)
}
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)
}
}