Parse -h, --help and --version and show help, version
This commit is contained in:
parent
b3290c357d
commit
2e1aee0313
1 changed files with 25 additions and 5 deletions
30
main.go
30
main.go
|
@ -10,19 +10,39 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var executableName string
|
||||||
var logger Logger
|
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() {
|
func main() {
|
||||||
// get cli arguments
|
// get cli arguments
|
||||||
args := os.Args
|
args := os.Args
|
||||||
|
executableName = args[0]
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
fmt.Printf( "Usage: %v <configfile>\n\nIf the config file doesn't exist, an incomplete \n" +
|
showHelp()
|
||||||
"configuration with default values is created.\n\nVersion: %s\n",
|
|
||||||
args[0],
|
|
||||||
Version)
|
|
||||||
os.Exit(1)
|
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
|
// create logger
|
||||||
logger = NewLogger(2)
|
logger = NewLogger(2)
|
||||||
// init
|
// init
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue