diff --git a/Makefile b/Makefile index 3a0484c..a69ae7e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ +# Note: git tags *must* be annotated for this to work +VERSION := $(shell git describe --tags `git rev-list --tags --max-count=1` | sed 's/^[^0-9]*//') + all: instafeed instafeed: - @go build -mod=vendor + @go build -mod=vendor -ldflags "-s -w -X main.version=$(VERSION)" -o instafeed + \ No newline at end of file diff --git a/instafeed.go b/instafeed.go index 0af948b..6891bff 100644 --- a/instafeed.go +++ b/instafeed.go @@ -22,6 +22,9 @@ var ( configFile string listFile string feedMaxItems int + showVersion bool + + version string ) func init() { @@ -32,8 +35,14 @@ func init() { flag.StringVar(&configFile, "f", path.Join(os.Getenv("HOME"), ".instafeed"), "Path to file where to store profile configuration") flag.StringVar(&listFile, "l", "", "Path to file containing list of Instagram users") + flag.BoolVar(&showVersion, "v", false, "Show version and exit") flag.IntVar(&feedMaxItems, "n", 20, "Number of user feed items") flag.Parse() + + if showVersion { + fmt.Println("instafeed", version) + os.Exit(0) + } } func main() {