Skip to content

Commit 142e6e4

Browse files
Merge pull request #45 from NETWAYS/version-flag
Version flag
2 parents c679414 + 444871e commit 142e6e4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ GO_LINKEROPTS := -ldflags $(GO_LINKERFLAGS)
2222
GO_FILES = $(shell find . -iname '*.go')
2323

2424
build:
25-
go build
25+
go build $(GO_LINKEROPTS)
2626

2727
build-all: $(TARGET_arm6) $(TARGET_amd64) $(TARGET_386) $(TARGET_arm64) $(TARGET_riscv64)
2828

cmd/root.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ func init() {
5252

5353
flagSet := rootCmd.Flags()
5454
flagSet.Bool("dump-icinga2-config", false, "Dump icinga2 config for this plugin")
55+
56+
flagSet.Bool("version", false, "Display version and other information about this program")
5557
}
5658

5759
func RunFunction(cmd *cobra.Command, args []string) {
5860
flagSet := cmd.Flags()
5961

6062
dumpConfig, err := flagSet.GetBool("dump-icinga2-config")
61-
6263
if err != nil {
6364
check.ExitError(err)
6465
}
@@ -68,6 +69,16 @@ func RunFunction(cmd *cobra.Command, args []string) {
6869
os.Exit(check.OK)
6970
}
7071

72+
showVersion, err := flagSet.GetBool("version")
73+
if err != nil {
74+
check.ExitError(err)
75+
}
76+
77+
if showVersion {
78+
fmt.Println(cmd.Version)
79+
os.Exit(check.OK)
80+
}
81+
7182
Help(cmd, args)
7283
}
7384

0 commit comments

Comments
 (0)