summaryrefslogtreecommitdiff
path: root/auto.Complete.go
diff options
context:
space:
mode:
Diffstat (limited to 'auto.Complete.go')
-rw-r--r--auto.Complete.go209
1 files changed, 0 insertions, 209 deletions
diff --git a/auto.Complete.go b/auto.Complete.go
index 4de01db..b844e5b 100644
--- a/auto.Complete.go
+++ b/auto.Complete.go
@@ -6,139 +6,14 @@ import (
"fmt"
"os"
"path/filepath"
- "strconv"
"strings"
"time"
"go.wit.com/dev/alexflint/arg"
"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"
)
-// makes a bash autocomplete file for your command
-func (pb *Auto) doHandlePB() error {
- homeDir, err := os.UserHomeDir()
- if err != nil {
- return err
- }
- basedir := filepath.Join(homeDir, ".cache/autocomplete")
- os.MkdirAll(basedir, os.ModePerm)
- fullname := filepath.Join(basedir, pb.Argname+".pb")
-
- all := NewAutos()
- var last *Auto
- data, err := os.ReadFile(fullname)
- if err == nil {
- err = all.Unmarshal(data)
- if err == nil {
- for found := range all.IterAll() {
- dur := time.Since(found.Ctime.AsTime())
- pb.Duration = durationpb.New(dur)
- // found.PrintDebug()
- 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'", 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
- }
- }
- }
-
- if all.Len() > 15 {
- pb.Debugf("DEBUG: trim() history is over 100 len=%d vs new=%d", all.Len(), all.Len()-90)
- all.Autos = all.Autos[all.Len()-10:]
- // newall.Autos = all.Autos[0:10]
- // for _, found := range all.Autos[0:10] {
- // newall.Append(found)
- // }
- }
-
- // need this for the first time the user runs autocomplete
- if last == nil {
- last = new(Auto)
- }
-
- now := time.Now()
- pb.Ctime = timestamppb.New(now)
- duration := time.Since(last.Ctime.AsTime())
- all.Append(pb)
-
- data, err = all.Marshal()
- if err != nil {
- return err
- }
-
- f, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
- defer f.Close()
- if err != nil {
- return err
- }
- _, err = f.Write(data)
- pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d len(data)=%d dur=%v err=%v", fullname, all.Len(), len(data), duration, err)
- return err
-}
-
-func (pb *Auto) SubCommand(cmd ...string) {
- partial := strings.Trim(pb.Partial, "'")
- if pb.Debug {
- if myAuto.examples == nil {
- pb.Debugf("WRITE DEBUG: argv.Examples() not defined")
- // log.Fprintf(os.Stderr, "\n")
- // log.Fprintf(os.Stderr, "examples was nil\n")
- // log.Fprintf(os.Stderr, "\n")
- } else {
- log.Fprintf(os.Stderr, "\n")
- log.Fprintf(os.Stderr, "\n")
- log.Fprintf(os.Stderr, "Examples:\n")
- for _, line := range strings.Split(myAuto.examples(), "\n") {
- log.Fprintf(os.Stderr, " %s\n", line)
- }
- // log.Fprintf(os.Stderr, "\n")
- }
- myAuto.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...)
- // myAuto.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd)
- // myAuto.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
- } else {
- f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- myAuto.pp.WriteHelpForAutocomplete(f, os.Stdout, partial, cmd...)
- // myAuto.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
- }
- os.Exit(0)
- // SubCommand(cmd)
-}
-
-/*
-func (pb *Auto) SubCommandShow() {
- partial := strings.Trim(pb.Partial, "'")
- if pb.Debug {
- myAuto.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, "show", "repo")
- } else {
- f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- myAuto.pp.WriteHelpForAutocomplete(f, os.Stdout, partial, "show", "repo")
- }
- os.Exit(0)
-}
-
-func (pb *Auto) SubCommand2(cmd string, addmatch []string) {
- partial := strings.Trim(pb.Partial, "'")
- if pb.Debug {
- // myAuto.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, pb.Cmd)
- myAuto.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, "", "")
- // myAuto.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd)
- // myAuto.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
- } else {
- f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- myAuto.pp.WriteHelpForAutocomplete(f, os.Stdout, partial, pb.Cmd)
- // myAuto.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
- }
- os.Exit(0)
- // SubCommand(cmd)
-}
-*/
-
// todo: move everything to this?
func (pb *Auto) Autocomplete3(sendthis []string) {
pb.Autocomplete2(strings.Join(sendthis, " "))
@@ -422,87 +297,3 @@ func doBash(argname string) {
}
os.Exit(0)
}
-
-func (pb *Auto) Version() string {
- return pb.getVersion()
-}
-
-func doVersion(pb *Auto) {
- log.Info(pb.getVersion())
- os.Exit(0)
-}
-
-func (pb *Auto) getVersion() string {
- if myAuto.buildtime == nil {
- return "app doesn't have argv.BuildVersion()"
- }
- 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(), , 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)
-}