Skip to content

Commit

Permalink
Merge pull request #48 from kpetremann/version_flag
Browse files Browse the repository at this point in the history
feat: add version flag
  • Loading branch information
kpetremann authored Jul 19, 2023
2 parents 06bbebd + 166d34d commit fe1005a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 12 additions & 1 deletion cmd/salt-exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"flag"
"fmt"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -48,8 +49,8 @@ type Config struct {

func parseFlags() bool {
// flags
versionCmd := flag.Bool("version", false, "print version")
flag.String("log-level", defaultLogLevel, "log level (debug, info, warn, error, fatal, panic, disabled)")

flag.String("host", "", "listen address")
flag.Int("port", defaultPort, "listen port")
flag.String("ipc-file", listener.DefaultIPCFilepath, "file location of the salt-master event bus")
Expand All @@ -68,6 +69,16 @@ func parseFlags() bool {
"[DEPRECATED] apply filter on states to monitor, separated by a comma")
flag.Parse()

if *versionCmd {
if version == "unknown" {
version = fmt.Sprintf("v%s", version)
}
fmt.Println("Version:", version)
fmt.Println("Build date:", date)
fmt.Println("Commit:", commit)
os.Exit(0)
}

return *healthMinions
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/salt-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
const configFileName = "config.yml"

var (
version = ""
commit = ""
version = "unknown"
commit = "unknown"
date = "unknown"
)

Expand Down
11 changes: 9 additions & 2 deletions cmd/salt-live/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ import (
tea "github.com/charmbracelet/bubbletea"
)

var version = "development"
var version = "unknown"
var commit = "unknown"
var date = "unknown"

func printVersion() {
fmt.Println("Version: ", version)
if version == "unknown" {
version = fmt.Sprintf("v%s", version)
}
fmt.Println("Version:", version)
fmt.Println("Build date:", date)
fmt.Println("Commit:", commit)
}

func main() {
Expand Down

0 comments on commit fe1005a

Please sign in to comment.