package main import ( "fmt" "os" "path/filepath" "nocternity.net/gomonop/cmd/sslcert" "nocternity.net/gomonop/cmd/zoneserial" "nocternity.net/gomonop/pkg/program" "nocternity.net/gomonop/pkg/version" ) var ( programs map[string]program.Builder = map[string]program.Builder{ "check_ssl_certificate": sslcert.NewProgram, "check_zone_serial": zoneserial.NewProgram, } ) func getProgram() program.Program { ownName := filepath.Base(os.Args[0]) if builder, ok := programs[ownName]; ok { return builder() } if len(os.Args) < 2 { fmt.Printf("Syntax: %s [arguments]\n", ownName) fmt.Printf(" %s --programs|-p\n", ownName) fmt.Printf(" %s --version|-v", ownName) } switch os.Args[1] { case "--programs", "-p": for name := range programs { fmt.Println(name) } os.Exit(0) case "--version", "-v": fmt.Printf("%s %s\n", ownName, version.Version()) os.Exit(0) } if builder, ok := programs[os.Args[1]]; ok { os.Args = os.Args[1:] return builder() } fmt.Printf("Unknown program: %s\n", os.Args[1]) os.Exit(1) return nil } func main() { program := getProgram() defer program.Done() if program.CheckArguments() { program.RunCheck() } }