gomonop/main.go

60 lines
1.3 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"path/filepath"
2024-07-19 14:55:23 +02:00
"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 {
2024-07-19 14:55:23 +02:00
exitError(
""+
"Syntax: %s <program> [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 {
2024-07-19 14:55:23 +02:00
fmt.Println(name)
}
os.Exit(0)
} else if os.Args[1] == "--version" || os.Args[1] == "-v" {
2024-07-19 14:55:23 +02:00
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()
}
}