From 36f7422d2fc62e5d84726633b2bb9ca07b75b555 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 12 Oct 2025 02:33:41 -0500 Subject: better name --- auto.Complete.go | 106 ------------------------------------------------------- sendStrings.go | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 106 deletions(-) delete mode 100644 auto.Complete.go create mode 100644 sendStrings.go diff --git a/auto.Complete.go b/auto.Complete.go deleted file mode 100644 index 19ccc30..0000000 --- a/auto.Complete.go +++ /dev/null @@ -1,106 +0,0 @@ -package prep - -// initializes logging and command line options - -import ( - "fmt" - "os" - "strings" - "time" - - "go.wit.com/log" -) - -// deprecate -func (pb *Auto) Autocomplete3(sendthis []string) { - pb.SendStrings(sendthis) -} - -// deprecate -func (pb *Auto) Autocomplete2(sendthis string) { - pb.SendStrings(strings.Split(sendthis, " ")) -} - -func (pb *Auto) SendString(sendthis string) { - pb.SendStrings(strings.Split(sendthis, " ")) -} - -// this is the user's application sending us strings we need to send to bash -func (pb *Auto) SendStrings(parts []string) { - dur := pb.Duration.AsDuration() - 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, config.FormatDuration(dur)) - pb.PrintDebug() - fmt.Println(" ") - */ - if myAuto.pp == nil { - pb.Debugf("myAuto.pp == nil") - } else { - pb.Debugf("myAuto.pp != nil") - if pb.Cmd == "" { - myAuto.pp.WriteHelp(os.Stderr) - } else { - myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd) - } - } - } - - // parts := strings.Split(sendthis, " ") - var all []string - for _, part := range parts { - var found bool - for _, s := range os.Args { - if s == part { - found = true - } - } - if found { - continue - } - all = append(all, part) - } - fmt.Printf("%s", strings.Join(all, " ")) - /* - if dur > time.Millisecond*200 { - if dur < time.Millisecond*800 { - // fmt.Println("a b") - fmt.Println(pb.Partial + " hello world") - } - } - */ -} - -// try out a new name. also, this whole thing is dumb and needs to be redone -func (pb *Auto) GenerateSubCommandStrings(cmd ...string) { - pb.SubCommand(cmd...) -} - -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) -} diff --git a/sendStrings.go b/sendStrings.go new file mode 100644 index 0000000..19ccc30 --- /dev/null +++ b/sendStrings.go @@ -0,0 +1,106 @@ +package prep + +// initializes logging and command line options + +import ( + "fmt" + "os" + "strings" + "time" + + "go.wit.com/log" +) + +// deprecate +func (pb *Auto) Autocomplete3(sendthis []string) { + pb.SendStrings(sendthis) +} + +// deprecate +func (pb *Auto) Autocomplete2(sendthis string) { + pb.SendStrings(strings.Split(sendthis, " ")) +} + +func (pb *Auto) SendString(sendthis string) { + pb.SendStrings(strings.Split(sendthis, " ")) +} + +// this is the user's application sending us strings we need to send to bash +func (pb *Auto) SendStrings(parts []string) { + dur := pb.Duration.AsDuration() + 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, config.FormatDuration(dur)) + pb.PrintDebug() + fmt.Println(" ") + */ + if myAuto.pp == nil { + pb.Debugf("myAuto.pp == nil") + } else { + pb.Debugf("myAuto.pp != nil") + if pb.Cmd == "" { + myAuto.pp.WriteHelp(os.Stderr) + } else { + myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd) + } + } + } + + // parts := strings.Split(sendthis, " ") + var all []string + for _, part := range parts { + var found bool + for _, s := range os.Args { + if s == part { + found = true + } + } + if found { + continue + } + all = append(all, part) + } + fmt.Printf("%s", strings.Join(all, " ")) + /* + if dur > time.Millisecond*200 { + if dur < time.Millisecond*800 { + // fmt.Println("a b") + fmt.Println(pb.Partial + " hello world") + } + } + */ +} + +// try out a new name. also, this whole thing is dumb and needs to be redone +func (pb *Auto) GenerateSubCommandStrings(cmd ...string) { + pb.SubCommand(cmd...) +} + +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) +} -- cgit v1.2.3