Add program argument handling

This commit is contained in:
Felix Niederwanger 2022-02-08 11:50:27 +01:00
parent 1b63df4e4e
commit 2cb91cadb2
Signed by: phoenix
GPG key ID: 31860289A704FB3C

View file

@ -17,11 +17,32 @@ var hooks []Hook
type Handler func(http.ResponseWriter, *http.Request)
func usage() {
fmt.Println("weblug is a simple webhook receiver")
fmt.Printf("Usage: %s [OPTIONS] YAML1[,YAML2...]\n\n", os.Args[0])
fmt.Println("OPTIONS")
fmt.Println(" -h, --help Print this help message")
fmt.Println()
fmt.Println("The program loads the given yaml files for webhook definitions")
}
func main() {
cf.SetDefaults()
if err := cf.LoadYAML(("../../weblug.yaml")); err != nil {
fmt.Fprintf(os.Stderr, "yaml error: %s\n", err)
os.Exit(1)
if len(os.Args) < 2 {
usage()
}
for _, arg := range os.Args[1:] {
if arg == "" {
continue
} else if arg == "-h" || arg == "--help" {
usage()
os.Exit(0)
} else {
if err := cf.LoadYAML((arg)); err != nil {
fmt.Fprintf(os.Stderr, "yaml error: %s\n", err)
os.Exit(1)
}
}
}
if len(cf.Hooks) == 0 {