diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 74b51c8..7730bf5 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,6 +10,7 @@ builds: - -w - -X main.version={{.Version}} - -X main.gitCommit={{.ShortCommit}} + - -X main.binaryName={{.ProjectName}} targets: - linux_amd64 - linux_arm64 diff --git a/main/help.go b/main/help.go new file mode 100644 index 0000000..2feadf8 --- /dev/null +++ b/main/help.go @@ -0,0 +1,17 @@ +package main + +import ( + "flag" + "fmt" +) + +func programVersion() { + fmt.Fprintf(flag.CommandLine.Output(), "Version: %s\n Commit: %s\n", version, gitCommit) +} + +func programUsage() { + fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] hostname.or.ip.address\n\nFlags:\n", binaryName) + flag.PrintDefaults() + fmt.Fprintln(flag.CommandLine.Output()) + programVersion() +} diff --git a/main/main.go b/main/main.go index 0c4f452..b6a14d7 100644 --- a/main/main.go +++ b/main/main.go @@ -12,8 +12,10 @@ import ( ) var ( - cfg mffp.Config - version, gitCommit string + cfg mffp.Config + version = "development" + gitCommit = "" + binaryName = "mffprober" ) func printVersion(v, g string) { @@ -25,6 +27,7 @@ func init() { v, e bool h string ) + flag.Usage = func() { programUsage() } flag.StringVar(&h, "host", "", "DEPRECATED: Specify host name/address after the flags.") flag.DurationVar(&cfg.Interval, "interval", 10*time.Second, "Polling interval in seconds")