From 4dc83c39152c17d49458cb95b5036c832c3535ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rychli=C5=84ski=20Arkadiusz?= Date: Tue, 22 Nov 2022 18:22:55 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Dodanie=20wy=C5=9Bwietlania=20wersji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cfg/params.go | 2 ++ cmd/multisql/multisql.go | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cfg/params.go b/cfg/params.go index 0dd7b9f..883068b 100644 --- a/cfg/params.go +++ b/cfg/params.go @@ -18,6 +18,7 @@ type Parameters struct { LogFile string Verbose bool AskPass bool + Version bool } var params Parameters @@ -30,6 +31,7 @@ func init() { flag.StringVar(¶ms.SqlDir, "sqldir", "scripts", "Katalog, w którym znajdują się skrypty do uruchomienia") flag.StringVar(¶ms.LogFile, "log", "", "Plik, do którego zostanie dopisany log programu") flag.BoolVar(¶ms.AskPass, "P", false, "Pytaj o hasło. Jeśli nie podane wymaga się hasła w ") + flag.BoolVar(¶ms.Version, "version", false, "Wypisuje wersję i kończy działanie") flag.Usage = printUsage flag.Parse() diff --git a/cmd/multisql/multisql.go b/cmd/multisql/multisql.go index efd2684..47ebb8b 100644 --- a/cmd/multisql/multisql.go +++ b/cmd/multisql/multisql.go @@ -2,7 +2,9 @@ package main import ( "flag" + "fmt" "os" + "runtime/debug" "strings" "baal.ar76.eu/x/pub/multisql/cfg" @@ -15,7 +17,10 @@ import ( func main() { log.SetFlags(log.LstdFlags) params := cfg.GetParams() - + if params.Version { + printVersion() + return + } args := flag.Args() if len (args) > 0 { encryption(args, params) @@ -109,3 +114,12 @@ func encryption(args []string, params cfg.Parameters) { log.Println("multisql decrypt hasła.zaszyfrowany hasła") } } + +func printVersion() { + bi, ok := debug.ReadBuildInfo() + if !ok { + log.Fatalf("Błąd odczytu informacji o wersji") + } + fmt.Fprintf(os.Stderr, "Wersja głównego modułu: %v\n", bi.Main.Version) + fmt.Fprintln(os.Stderr, bi) +}