Skip to content

Commit

Permalink
Merge pull request #120 from Hsn723/version-flag
Browse files Browse the repository at this point in the history
[feat] add --version flag and output version information
  • Loading branch information
Hsn723 authored Aug 28, 2024
2 parents 3677c43 + d384065 commit ff1b8c0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ import (
"net/http"
"os"

_ "embed"
"github.com/alecthomas/kingpin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
version string
commit string
date string
builtBy string

//go:embed VERSION
fallbackVersion string
)

func main() {
var (
ctx = context.Background()
app = kingpin.New("postfix_exporter", "Prometheus metrics exporter for postfix")
versionFlag = app.Flag("version", "Print version information").Bool()
listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9154").String()
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String()
Expand All @@ -24,6 +36,26 @@ func main() {
InitLogSourceFactories(app)
kingpin.MustParse(app.Parse(os.Args[1:]))

if version == "" {
version = fallbackVersion
}

if *versionFlag {
os.Stdout.WriteString(version)
os.Exit(0)
}
versionString := "postfix_exporter " + version
if commit != "" {
versionString += " (" + commit + ")"
}
if date != "" {
versionString += " built on " + date
}
if builtBy != "" {
versionString += " by: " + builtBy
}
log.Print(versionString)

logSrc, err := NewLogSourceFromFactories(ctx)
if err != nil {
log.Fatalf("Error opening log source: %s", err)
Expand Down

0 comments on commit ff1b8c0

Please sign in to comment.