summaryrefslogtreecommitdiff
path: root/complete.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-02 18:35:52 -0500
committerJeff Carr <[email protected]>2025-10-02 18:35:52 -0500
commit435b9fdee2f51170aacf21f14a0118c89c84e166 (patch)
treea30fdfd1bfa7db366be1a23ce80f0454c3bea9c1 /complete.go
parent45c1ecc507ab0943af87434b6661b2c3b7e1fa9e (diff)
make a smart argv() function
Diffstat (limited to 'complete.go')
-rw-r--r--complete.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/complete.go b/complete.go
index f0b1ef9..03440b2 100644
--- a/complete.go
+++ b/complete.go
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "strconv"
"strings"
"time"
@@ -221,6 +222,14 @@ func parseArgv(argname string) *Auto {
os.Exit(0)
}
+ if len(os.Args) > 1 && os.Args[1] == "--version" {
+ if myAuto.buildtime == nil {
+ // if binary defined buildtime() then process standard version output here
+ doVersion(pb)
+ os.Exit(0)
+ }
+ }
+
// should we do auto complete here?
if len(os.Args) > 1 && os.Args[1] == "--auto-complete" {
pb.IsAuto = true
@@ -391,3 +400,42 @@ func doBash(argname string) {
}
os.Exit(0)
}
+
+func doVersion(pb *Auto) {
+ if myAuto.buildtime == nil {
+ return
+ }
+ BUILDTIME, VERSION := myAuto.buildtime()
+
+ parts := strings.Split(BUILDTIME, ".")
+ if len(parts) == 1 {
+ // The input epoch seconds
+ // epochSeconds := int64(1758646486)
+ num, err := strconv.Atoi(BUILDTIME)
+ epochSeconds := int64(num)
+ if err == nil {
+
+ // 1. Convert the epoch seconds to a time.Time object.
+ // time.Unix() creates the time in the UTC timezone by default.
+ t := time.Unix(epochSeconds, 0)
+
+ // 2. Convert the UTC time to the computer's local timezone.
+ localTime := t.Local()
+
+ // 3. Print the result. The default format is clear and includes the timezone.
+ // fmt.Println("Default format:", localTime)
+ // For a more human-friendly format, use the Format() method.
+ // Go uses a special reference time for formatting: Mon Jan 2 15:04:05 2006 MST
+ // You lay out your desired format using these specific numbers.
+ // formattedString := localTime.Format("Monday, January 2, 2006 at 3:04:05 PM (MST)")
+ // fmt.Println(" Custom format:", formattedString)
+
+ // now := time.Now()
+ // dur := time.Since(localTime)
+ BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), shell.FormatDuration(time.Since(localTime)))
+ }
+ }
+
+ log.Infof("%s %s Built on %s\n", pb.Argname, VERSION, BUILDTIME)
+ os.Exit(0)
+}