Added version display feature in apg.go

An option flag has been added to apg.go, which allows users to check the version of the script. When activated, the script displays the version and exits. It also provides OS and architecture information, outputted to stderr for user convenience.
This commit is contained in:
Winni Neessen 2024-03-12 20:12:32 +01:00
parent c5caab0066
commit 1eb4cf37e2
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"os"
"runtime"
"src.neessen.cloud/wneessen/apg-go"
)
@ -24,7 +25,7 @@ func main() {
// See usage() for flag details
var algorithm int
var modeString string
var complexPass, humanReadable, lowerCase, numeric, special, upperCase bool
var complexPass, humanReadable, lowerCase, numeric, special, showVer, upperCase bool
flag.IntVar(&algorithm, "a", 1, "")
flag.BoolVar(&lowerCase, "L", false, "")
flag.Int64Var(&config.MinLowerCase, "mL", config.MinLowerCase, "")
@ -44,9 +45,20 @@ func main() {
flag.BoolVar(&config.SpellPassword, "l", false, "")
flag.BoolVar(&config.SpellPronounceable, "t", false, "")
flag.BoolVar(&config.CheckHIBP, "p", false, "")
flag.BoolVar(&showVer, "v", false, "")
flag.Usage = usage
flag.Parse()
// Show version and exit
if showVer {
_, _ = os.Stderr.WriteString(`apg-go // A "Automated Password Generator"-clone ` +
`v` + apg.VERSION + "\n")
_, _ = os.Stderr.WriteString("OS: " + runtime.GOOS + " // Arch: " +
runtime.GOARCH + " \n")
_, _ = os.Stderr.WriteString("(C) 2021-2024 by Winni Neessen\n")
os.Exit(0)
}
// Old style character modes
if humanReadable {
config.Mode = apg.MaskToggleMode(config.Mode, apg.ModeHumanReadable)