From f93fda720f5bf0a034e089793057c7fd2dc97c2e Mon Sep 17 00:00:00 2001 From: Robin Scherrer Date: Sun, 20 Feb 2022 14:00:43 +0100 Subject: [PATCH] Add flag for printing current version --- README.md | 1 + main.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 7f8e615..0ff1322 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ A small CLI tool to generate TOTP (Time-based One-time Password) tokens. ``` -s, --secretkey string supply a valid TOTP secret key to generate a token from + -v, --version print version and exit ``` diff --git a/main.go b/main.go index b849665..c28815e 100644 --- a/main.go +++ b/main.go @@ -3,14 +3,24 @@ package main import ( "fmt" "log" + "os" flag "github.com/spf13/pflag" "github.com/xlzd/gotp" ) +const version = "2.0.1" + func main() { secretKey := flag.StringP("secretkey", "s", "", "supply a valid TOTP secret key to generate a token from") + printVersion := flag.BoolP("version", "v", false, "Print the current version and exit") flag.Parse() + + if *printVersion { + fmt.Println(version) + os.Exit(0) + } + if *secretKey == "" { log.Fatal("secretkey cannot be empty") }