Skip to content

Commit

Permalink
feat: add -v option
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Apr 17, 2021
1 parent 51e2238 commit 42c1b3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions help.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Ayd? status monitoring service (version {{ .Version }})

Usage:
{{ .Command }} [-p NUMBER | -o FILE]... INTERVALS|TARGETS...
{{ .Command }} -1 [-o FILE] INTERVALS|TARGETS...
Expand Down
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import (
)

var (
listenPort = flag.Int("p", 9000, "Listen port of status page.")
storePath = flag.String("o", "./ayd.log", "Path to log file. Log file is also use for restore status history.")
oneshot = flag.Bool("1", false, "Check status only once and exit. Exit with 0 if all check passed, otherwise exit with code 1.")
alertURI = flag.String("a", "", "The alert URI that the same format as target URI.")
version = "0.1.0"

listenPort = flag.Int("p", 9000, "Listen port of status page.")
storePath = flag.String("o", "./ayd.log", "Path to log file. Log file is also use for restore status history.")
oneshot = flag.Bool("1", false, "Check status only once and exit. Exit with 0 if all check passed, otherwise exit with code 1.")
alertURI = flag.String("a", "", "The alert URI that the same format as target URI.")
showVersion = flag.Bool("v", false, "Show version and exit.")
)

//go:embed help.txt
Expand All @@ -31,6 +34,7 @@ func Usage() {
tmpl := template.Must(template.New("help.txt").Parse(helpText))
tmpl.Execute(flag.CommandLine.Output(), map[string]interface{}{
"Command": os.Args[0],
"Version": version,
"HTTPRedirectMax": probe.HTTP_REDIRECT_MAX,
})
}
Expand Down Expand Up @@ -185,6 +189,11 @@ func main() {
flag.Usage = Usage
flag.Parse()

if *showVersion {
fmt.Println("version:", version)
os.Exit(0)
}

tasks, errors := ParseArgs(flag.Args())
if errors != nil {
fmt.Fprintln(os.Stderr, "Invalid argument:")
Expand Down

0 comments on commit 42c1b3b

Please sign in to comment.