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.ProgramBuilder = map[string]program.ProgramBuilder{ "check_ssl_certificate": sslcert.NewProgram, "check_zone_serial": zoneserial.NewProgram, } ) func exitError(msg string, args ...interface{}) { fmt.Fprintf(os.Stderr, msg+"\n", args...) os.Exit(1) } func main() { ownName := filepath.Base(os.Args[0]) var program program.Program if builder, ok := programs[ownName]; ok { program = builder() } else if len(os.Args) < 2 { exitError( ""+ "Syntax: %s [arguments]\n"+ " %s --programs|-p\n"+ " %s --version|-v", os.Args[0], os.Args[0], os.Args[0]) } else if os.Args[1] == "--programs" || os.Args[1] == "-p" { for name := range programs { fmt.Println(name) } os.Exit(0) } else if os.Args[1] == "--version" || os.Args[1] == "-v" { fmt.Printf("gomonop %s\n", version.Version()) os.Exit(0) } else if builder, ok := programs[os.Args[1]]; ok { os.Args = os.Args[1:] program = builder() } else { exitError("Unknown program: %s", os.Args[1]) } defer program.Done() if program.CheckArguments() { program.RunCheck() } }