gomonop/main.go
Emmanuel BENOîT 2fa0e37900
All checks were successful
Run tests and linters / test (push) Successful in 43s
Run tests and linters / build (push) Successful in 41s
Run tests and linters / lint (push) Successful in 1m22s
refactor: reorganize project in order to include automation (#1)
Reviewed-on: #1
Co-authored-by: Emmanuel BENOÎT <tseeker@nocternity.net>
Co-committed-by: Emmanuel BENOÎT <tseeker@nocternity.net>
2024-07-19 22:01:34 +02:00

62 lines
1.2 KiB
Go

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 <program> [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()
}
}