diff options
Diffstat (limited to 'complete.go')
| -rw-r--r-- | complete.go | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/complete.go b/complete.go index bd9d46e..905ba8d 100644 --- a/complete.go +++ b/complete.go @@ -11,7 +11,7 @@ import ( "time" "go.wit.com/dev/alexflint/arg" - "go.wit.com/lib/gui/shell" + "go.wit.com/lib/config" "go.wit.com/log" durationpb "google.golang.org/protobuf/types/known/durationpb" timestamppb "google.golang.org/protobuf/types/known/timestamppb" @@ -40,7 +40,7 @@ func (pb *Auto) doHandlePB() error { cmd := fmt.Sprintf("cmd='%s'", found.Cmd) arglast := fmt.Sprintf("last='%s'", found.Last) partial := fmt.Sprintf("p='%s'", found.Partial) - age := fmt.Sprintf("age='%-6.6s'", shell.FormatDuration(dur)) + age := fmt.Sprintf("age='%-6.6s'", config.FormatDuration(dur)) pb.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) last = found } @@ -149,7 +149,7 @@ func (pb *Auto) Autocomplete2(sendthis string) { if dur < time.Millisecond*200 { pb.Debug = true /* - pb.Debugf("TODO: show extended help here '%s' '%s' %v dur=%v\n", pb.Arg0, pb.Arg1, pb.Argv, shell.FormatDuration(dur)) + pb.Debugf("TODO: show extended help here '%s' '%s' %v dur=%v\n", pb.Arg0, pb.Arg1, pb.Argv, config.FormatDuration(dur)) pb.PrintDebug() fmt.Println(" ") */ @@ -393,12 +393,12 @@ func doBash(argname string) { os.Exit(0) } filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname) - if shell.Exists(filename) { + if config.Exists(filename) { log.Fprintln(os.Stderr, "# file already exists", filename) // os.Exit(0) } basedir, _ := filepath.Split(filename) - if !shell.IsDir(basedir) { + if !config.IsDir(basedir) { os.MkdirAll(basedir, os.ModePerm) } @@ -451,11 +451,46 @@ func (pb *Auto) getVersion() string { // now := time.Now() // dur := time.Since(localTime) - // BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), , shell.FormatDuration(time.Since(localTime))) - stamp := log.Sprintf("Built %s Age(%s)", localTime.Format("2006-01-02 15:04"), shell.FormatDuration(time.Since(localTime))) + // BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), , config.FormatDuration(time.Since(localTime))) + stamp := log.Sprintf("Built %s Age(%s)", localTime.Format("2006-01-02 15:04"), config.FormatDuration(time.Since(localTime))) return fmt.Sprintf("%s %s %s", pb.Argname, VERSION, stamp) } } return fmt.Sprintf("%s %s Built on %s", pb.Argname, VERSION, BUILDTIME) } + +func StandardVersion(ARGNAME, VERSION, BUILDTIME string) string { + 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(), , config.FormatDuration(time.Since(localTime))) + stamp := log.Sprintf("Built %s Age(%s)", localTime.Format("2006-01-02 15:04"), config.FormatDuration(time.Since(localTime))) + return fmt.Sprintf("%s %s %s", ARGNAME, VERSION, stamp) + } + } + + return fmt.Sprintf("%s %s Built on %s", ARGNAME, VERSION, BUILDTIME) +} |
