Parse -h, --help and --version and show help, version

This commit is contained in:
ChaoticByte 2025-06-11 17:45:14 +02:00
parent b3290c357d
commit 2e1aee0313
No known key found for this signature in database

30
main.go
View file

@ -10,19 +10,39 @@ import (
"time"
)
var executableName string
var logger Logger
func showVersion() {
fmt.Printf("wid-notifier %s\n", Version)
}
func showHelp() {
fmt.Printf("Usage: %v <configfile>\n\nIf the config file doesn't exist, an incomplete \n" +
"configuration with default values is created.\n\n",
executableName)
showVersion()
}
func main() {
// get cli arguments
args := os.Args
executableName = args[0]
if len(args) < 2 {
fmt.Printf( "Usage: %v <configfile>\n\nIf the config file doesn't exist, an incomplete \n" +
"configuration with default values is created.\n\nVersion: %s\n",
args[0],
Version)
showHelp()
os.Exit(1)
}
configFilePath := os.Args[1]
for _, arg := range args {
if arg == "-h" || arg == "--help" {
showHelp()
os.Exit(0)
} else if arg == "--version" {
showVersion()
os.Exit(0)
}
}
configFilePath := args[1]
// create logger
logger = NewLogger(2)
// init