From 5e2efb55c601bfff8b005f43ec65ac1bc79e0efc Mon Sep 17 00:00:00 2001 From: Marko Milivojevic Date: Fri, 26 Nov 2021 21:20:51 -0800 Subject: [PATCH] Improve help text. --- .goreleaser.yaml | 1 + main/help.go | 17 +++++++++++++++++ main/main.go | 7 +++++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 main/help.go 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")