Skip to content

Commit

Permalink
Add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 8, 2022
1 parent 64a6a3f commit 4de4936
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import (
)

var (
// Version contains the application version number. It's set via ldflags
// when building.
Version = ""

// CommitSHA contains the SHA of the commit that this application was built
// against. It's set via ldflags when building.
CommitSHA = ""

deck *Deck

dbusConn *dbus.Conn
Expand All @@ -32,6 +40,7 @@ var (
brightness = flag.Uint("brightness", 80, "brightness in percent")
sleep = flag.String("sleep", "", "sleep timeout")
verbose = flag.Bool("verbose", false, "verbose output")
version = flag.Bool("version", false, "display version")
)

const (
Expand Down Expand Up @@ -261,6 +270,23 @@ func run() error {
func main() {
flag.Parse()

if *version {
if len(CommitSHA) > 7 {
CommitSHA = CommitSHA[:7]
}
if Version == "" {
Version = "(built from source)"
}

fmt.Printf("deckmaster %s", Version)
if len(CommitSHA) > 0 {
fmt.Printf(" (%s)", CommitSHA)
}

fmt.Println()
os.Exit(0)
}

if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down

0 comments on commit 4de4936

Please sign in to comment.