summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 01:34:03 -0500
committerJeff Carr <[email protected]>2025-10-12 01:34:03 -0500
commitd04e274fc0d0a6ae11add130cf5c40d5eedb2570 (patch)
treeb1a5175fd6253d1bf8a82349c3352ea2f87a6da6
parent391de1095ed5663ec224bcc1cfaa17bcba4c5b25 (diff)
more house cleaning
-rw-r--r--auto.Complete.go70
-rw-r--r--doHandlePB.go60
-rw-r--r--interface.go16
3 files changed, 84 insertions, 62 deletions
diff --git a/auto.Complete.go b/auto.Complete.go
index 633d3e6..c99c1bf 100644
--- a/auto.Complete.go
+++ b/auto.Complete.go
@@ -7,8 +7,15 @@ import (
"os"
"strings"
"time"
+
+ "go.wit.com/log"
)
+// this is the user's application sending us strings we need to send to bash
+func (pb *Auto) SendStrings(sendthis []string) {
+ pb.Autocomplete2(strings.Join(sendthis, " "))
+}
+
// todo: move everything to this?
func (pb *Auto) Autocomplete3(sendthis []string) {
pb.Autocomplete2(strings.Join(sendthis, " "))
@@ -59,3 +66,66 @@ func (pb *Auto) Autocomplete2(sendthis string) {
}
*/
}
+
+// 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)
+ // 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)
+}
+*/
diff --git a/doHandlePB.go b/doHandlePB.go
index b27d3e5..a916a9f 100644
--- a/doHandlePB.go
+++ b/doHandlePB.go
@@ -6,11 +6,9 @@ import (
"fmt"
"os"
"path/filepath"
- "strings"
"time"
"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"
)
@@ -78,61 +76,3 @@ func (pb *Auto) doHandlePB() error {
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)
-}
-*/
diff --git a/interface.go b/interface.go
index 09461b1..0dad2ac 100644
--- a/interface.go
+++ b/interface.go
@@ -10,12 +10,19 @@ type appnameI interface {
Appname() string
}
+// deprecate
type autoFuncI interface {
// Version returns the version string that will be printed on a line by itself
// at the top of the help message.
DoAutoComplete(*Auto)
}
+type sendCompletionStringsI interface {
+ // Version returns the version string that will be printed on a line by itself
+ // at the top of the help message.
+ SendCompletionStrings(*Auto)
+}
+
type buildtimeI interface {
Buildtime() (string, string)
}
@@ -27,8 +34,7 @@ type examplesI interface {
}
type exitI interface {
- // Version returns the version string that will be printed on a line by itself
- // at the top of the help message.
+ // allows a custom app Exit()
Exit()
}
@@ -58,6 +64,12 @@ func findAppInfo(tmp interface{}) {
// panic("you need to make the function argv.DoAutoComplete()")
}
+ if tmp, ok := tmp.(sendCompletionStringsI); ok {
+ myAuto.autoFunc = tmp.SendCompletionStrings
+ } else {
+ // panic("you need to make the function argv.DoAutoComplete()")
+ }
+
if tmp, ok := tmp.(exitI); ok {
myAuto.appExit = tmp.Exit
} else {