Skip to content

Commit c9b4968

Browse files
authored
Re-add the -version Flag (#135)
The flag was still mentioned in the readme, but was not availble anymore. This commit re-adds the flag and adjusts the usage instructions in the readme.
1 parent 86ab6fb commit c9b4968

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ VERSION ?= $(shell git describe --tags)
77
REVISION ?= $(shell git rev-parse HEAD)
88
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
99
BUILDUSER ?= $(shell id -un)
10-
BUILDTIME ?= $(shell date '+%Y%m%d-%H:%M:%S')
10+
BUILDTIME ?= $(shell date '+%Y-%m-%d@%H:%M:%S')
1111

1212
.PHONY: build build-darwin-amd64 build-linux-amd64 build-linux-armv7 build-linux-arm64 build-windows-amd64 clean release release-major release-minor release-patch
1313

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ The script_exporter is configured via a configuration file and command-line flag
4848

4949
```txt
5050
Usage of ./bin/script_exporter:
51+
-config.check
52+
Do not run the exporter. Only check the configuration file and exit (0 if the Configuration file is valid, 1 otherwise).
5153
-config.file file
5254
Configuration file in YAML format. (default "config.yaml")
5355
-create-token
5456
Create bearer token for authentication.
57+
-log.env
58+
Log environment variables used by a script.
59+
-log.format string
60+
Output format of log messages. One of: [logfmt, json] (default "logfmt")
61+
-log.level string
62+
Only log messages with the given severity or above. One of: [debug, info, warn, error] (default "info")
63+
-noargs
64+
Restrict script to accept arguments, for security issues
5565
-timeout-offset seconds
5666
Offset to subtract from Prometheus-supplied timeout in seconds. (default 0.5)
5767
-version
58-
Show version information.
68+
Print version information.
5969
-web.listen-address string
6070
Address to listen on for web interface and telemetry. (default ":9469")
6171
```

pkg/exporter/exporter.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func InitExporter() (e *Exporter) {
104104
logFormat := flag.String("log.format", "logfmt", "Output format of log messages. One of: [logfmt, json]")
105105
logEnv := flag.Bool("log.env", false, "Log environment variables used by a script.")
106106
configCheck := flag.Bool("config.check", false, "Do not run the exporter. Only check the configuration file and exit (0 if the Configuration file is valid, 1 otherwise).")
107+
printVersion := flag.Bool("version", false, "Print version information.")
107108

108109
flag.Parse()
109110

@@ -124,6 +125,17 @@ func InitExporter() (e *Exporter) {
124125
os.Exit(1)
125126
}
126127

128+
if *printVersion {
129+
v, err := version.Print("script_exporter")
130+
if err != nil {
131+
level.Error(logger).Log("Failed to print version information", "err", err)
132+
os.Exit(1)
133+
}
134+
135+
fmt.Fprintln(os.Stdout, v)
136+
os.Exit(0)
137+
}
138+
127139
// Avoid problems by erroring out if we have any remaining
128140
// arguments, instead of silently ignoring them.
129141
if len(flag.Args()) != 0 {

0 commit comments

Comments
 (0)