From 8497362a52b80026ecbd29a51d13013c7d07eeaa Mon Sep 17 00:00:00 2001 From: ewy Date: Tue, 14 Apr 2026 19:52:44 +0200 Subject: add version flag --- flags/flags.go | 17 +++++++++-------- main.go | 10 ++++++++++ version.txt | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 version.txt diff --git a/flags/flags.go b/flags/flags.go index 19cc84b..a513019 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -3,12 +3,13 @@ package flags import "github.com/spf13/pflag" var ( - Here = pflag.BoolP("here", "h", false, "run target in current directory instead of source location") - At = pflag.StringP("at", "@", "", "override run location") - Single = pflag.BoolP("singgle", "s", false, "do not run any triggers") - All = pflag.BoolP("all", "a", false, "get sources from cache instead of crawling") - Dry = pflag.BoolP("dry", "d", false, "print cmdlines instead of running them") - Root = pflag.BoolP("root", "r", false, "run targets (including triggers) with sudo") - Yes = pflag.BoolP("yes", "y", false, "auto-confirm y/n confirmations") - Env = pflag.StringArray("env", nil, "environment files or pre- or suffix") + Here = pflag.BoolP("here", "h", false, "run target in current directory instead of source location") + At = pflag.StringP("at", "@", "", "override run location") + Single = pflag.BoolP("singgle", "s", false, "do not run any triggers") + All = pflag.BoolP("all", "a", false, "get sources from cache instead of crawling") + Dry = pflag.BoolP("dry", "d", false, "print cmdlines instead of running them") + Root = pflag.BoolP("root", "r", false, "run targets (including triggers) with sudo") + Yes = pflag.BoolP("yes", "y", false, "auto-confirm y/n confirmations") + Env = pflag.StringArray("env", nil, "environment files or pre- or suffix") + Version = pflag.BoolP("version", "v", false, "print version and exit") ) diff --git a/main.go b/main.go index ce8ea95..35acc94 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + _ "embed" "github.com/spf13/pflag" "os" "pik/cache" @@ -37,8 +38,17 @@ var hydrators = []model.Hydrator{ var ForceConfirm = false +// go:embed version.txt +var version string + func main() { pflag.Parse() + + if *flags.Version { + _, _ = spool.Print("%s\n", version) + os.Exit(0) + } + for _, i := range initializers { err := i.Init() if err != nil { diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file -- cgit v1.3