diff --git a/.goreleaser.yml b/.goreleaser.yml index 5564d2c..d9e0a13 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -19,7 +19,7 @@ builds: - linux id: pominal-build ldflags: - - s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.goversion={{.Env.GOVERSION}} + - "-s -w -X main.version={{ .Version }} -X main.commit={{ .ShortCommit }} -X main.date={{ .Date }} -X main.goversion={{ .Env.GOVERSION }}" archives: - files: diff --git a/main.go b/main.go index e02b055..4b36d6b 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ var ( shortBreakTimer string longBreakTimer string maxWorkCycles int + printVersion bool ) func init() { @@ -47,6 +48,7 @@ func init() { flag.StringVar(&shortBreakTimer, "short-break-timer", "5m", "sets the timer for your short break.") flag.StringVar(&longBreakTimer, "long-break-timer", "20m", "sets the timer for your long break.") flag.IntVar(&maxWorkCycles, "max-work-cycles", 4, "sets the maximum number of work cycles to complete before taking a long break.") + flag.BoolVar(&printVersion, "version", false, "print version and exit.") flag.Parse() } @@ -63,6 +65,11 @@ type Pominal struct { func main() { + if printVersion { + Version() + os.Exit(0) + } + workTimeDuration, err := time.ParseDuration(workTimer) if err != nil { fmt.Printf("ERROR: Unable to set the work timer. %s", err.Error()) diff --git a/version.go b/version.go index 0c950ae..27615d9 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,21 @@ +/* + Pominal + Copyright (C) 2019 Daniel Anglin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + package main import "fmt" @@ -10,5 +28,5 @@ var ( ) func Version() { - fmt.Printf("Version: %s\nCommit: %s\nGo Version: %s\nDate: %s", version, commit, goversion, date) + fmt.Printf("Pominal\n\nVersion: %s\nCommit: %s\nGo Version: %s\nDate: %s", version, commit, goversion, date) }