diff options
| author | Jeff Carr <[email protected]> | 2025-10-24 11:28:43 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-24 11:28:43 -0500 | 
| commit | 88d0ce908c76d98a29ab5ffc3417248f951493fb (patch) | |
| tree | b50a0917f1a1d713fdb5addc6e65dd2842b98fe9 | |
| parent | 2b46985ae8def4ff5779fbc027a6ddbe7a1a6a8d (diff) | |
removing log from herev0.0.44
| -rw-r--r-- | argv.Print.go | 24 | ||||
| -rw-r--r-- | argv.SendStrings.go | 8 | ||||
| -rw-r--r-- | argv.Version.go | 7 | ||||
| -rw-r--r-- | argv.parseOsArgs.go | 24 | ||||
| -rw-r--r-- | exit.go | 11 | ||||
| -rw-r--r-- | gui.go | 18 | ||||
| -rw-r--r-- | init.go | 6 | ||||
| -rw-r--r-- | makeAutocompleteFiles.bash.go | 7 | ||||
| -rw-r--r-- | makeAutocompleteFiles.zsh.go | 4 | ||||
| -rw-r--r-- | notsure.go | 8 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 46 | 
11 files changed, 93 insertions, 70 deletions
diff --git a/argv.Print.go b/argv.Print.go index 9429a01..7cfbcff 100644 --- a/argv.Print.go +++ b/argv.Print.go @@ -5,6 +5,7 @@ package argvpb  import (  	"fmt" +	"os"  	"strings"  	"go.wit.com/lib/cobol" @@ -47,3 +48,26 @@ func (all *Argvs) PrintHistory() {  		pb.PrintDebugNew("HIST")  	}  } + +func (pb *Argv) PrintStderr() { +	if !me.debug { +		os.Exit(0) +	} +	lines := strings.Split(strings.TrimSpace(pb.Stderr), "\n") +	if len(lines) == 0 { +		os.Exit(0) +	} +	fmt.Fprintf(os.Stderr, "\n") +	for _, line := range lines { +		line = strings.TrimSpace(line) +		if line == "" { +			continue +		} +		fmt.Fprintf(os.Stderr, "%s\n", line) +	} +} + +func (pb *Argv) PrintStderrExit() { +	pb.PrintStderr() +	os.Exit(0) +} diff --git a/argv.SendStrings.go b/argv.SendStrings.go index 4192ba0..b523120 100644 --- a/argv.SendStrings.go +++ b/argv.SendStrings.go @@ -8,8 +8,6 @@ import (  	"fmt"  	"os"  	"strings" - -	"go.wit.com/log"  )  // the application must send a string "help run list" @@ -33,7 +31,7 @@ func (pb *Argv) SendStrings(parts []string) {  		}  		all = append(all, part)  	} -	fmt.Printf("%s", strings.Join(all, " ")) +	pb.Stdout = fmt.Sprintf("%s", strings.Join(all, " "))  }  // try out a new name. also, this whole thing is dumb and needs to be redone @@ -45,9 +43,9 @@ func (pb *Argv) SubCommand(cmd ...string) {  	if me.examples == nil {  		pb.Debugf("WRITE DEBUG: argv.Examples() not defined")  	} else { -		pb.Stderr += log.Sprintf("Examples:\n") +		pb.Stderr += fmt.Sprintf("Examples:\n")  		for _, line := range strings.Split(me.examples(), "\n") { -			pb.Stderr += log.Sprintf("  %s\n", line) +			pb.Stderr += fmt.Sprintf("  %s\n", line)  		}  	}  	partial := strings.Trim(pb.Partial, "'") diff --git a/argv.Version.go b/argv.Version.go index 4a133c2..e54fb3e 100644 --- a/argv.Version.go +++ b/argv.Version.go @@ -5,7 +5,6 @@ import (  	"os"  	"go.wit.com/lib/cobol" -	"go.wit.com/log"  )  func (pb *Argv) Version() string { @@ -13,7 +12,7 @@ func (pb *Argv) Version() string {  }  func doVersion(pb *Argv) { -	log.Info(pb.AppInfo.getVersion()) +	fmt.Println(pb.AppInfo.getVersion())  	os.Exit(0)  } @@ -21,12 +20,12 @@ func (info *App) getVersion() string {  	var s string  	timeString, t, err := cobol.TimeCheck(info.BUILDTIME)  	if t != nil { -		// log.Printf("TIME getVersion(t != nil) ERR=(%v) t=(%v) AppInfo.BUILTIME is=(%v)\n", err, t, info.BUILDTIME) +		// fmt.Printf("TIME getVersion(t != nil) ERR=(%v) t=(%v) AppInfo.BUILTIME is=(%v)\n", err, t, info.BUILDTIME)  		return fmt.Sprintf("%s %s    Built on %s", info.APPNAME, info.VERSION, cobol.Time(t))  	} else if err == nil {  		s = fmt.Sprintf("%s %s    Built on %s (argv.had(%s))", info.APPNAME, info.VERSION, timeString, info.BUILDTIME)  	} else { -		log.Printf("TIME getVersion() ERR=(%v) timeString=(%v) AppInfo.BUILTIME was=(%v)\n", err, timeString, info.BUILDTIME) +		// fmt.Printf("TIME getVersion() ERR=(%v) timeString=(%v) AppInfo.BUILTIME was=(%v)\n", err, timeString, info.BUILDTIME)  		s = fmt.Sprintf("%s %s    Built on raw(%v) (argv had %s)", info.APPNAME, info.VERSION, timeString, info.BUILDTIME)  	}  	return s diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go index ac5be15..bf73744 100644 --- a/argv.parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -6,8 +6,6 @@ import (  	"fmt"  	"os"  	"strings" - -	"go.wit.com/log"  )  // todo: this is wrong @@ -82,20 +80,16 @@ func (pb *Argv) parseOsArgs() {  		}  	} -	// wtf is this. I've forgotten. todo: figure this out -	if len(os.Args) > 1 && os.Args[1] == pb.AppInfo.APPNAME { -		me.isAuto = true -		parts := strings.Split(os.Getenv("COMP_LINE"), " ") -		me.debug = true -		log.Fprintf(os.Stderr, "\n") -		pb.Debugf("MATCH Partial os.Args=%v COMP_LINE=%v", os.Args, os.Getenv("COMP_LINE")) -		// log.Fprintf(os.Stdout, "jcarr") -		if len(parts) > 0 { -			// pb.Arg0 = parts[0] +	/* +		// wtf is this. I've forgotten. todo: figure this out +		if len(os.Args) > 1 && os.Args[1] == pb.AppInfo.APPNAME { +			me.isAuto = true +			// parts := strings.Split(os.Getenv("COMP_LINE"), " ") +			me.debug = true +			pb.Debugf("MATCH Partial os.Args=%v COMP_LINE=%v", os.Args, os.Getenv("COMP_LINE")) +			os.Exit(0)  		} -		// pb.Arg1 = os.Args[1] -		os.Exit(0) -	} +	*/  	// print the version and exit  	if len(os.Args) > 1 && os.Args[1] == "--version" { @@ -6,7 +6,6 @@ import (  	"time"  	"go.wit.com/lib/cobol" -	"go.wit.com/log"  )  // since we know when the command starts (duh, this parses os.Args) @@ -35,7 +34,7 @@ func (pb *Argv) GoodExit(msg string) {  	} else {  		appname = pb.AppInfo.APPNAME  	} -	log.Infof("%s: %s (%s)\n", appname, msg, cobol.FormatDuration(dur)) +	fmt.Printf("%s: %s (%s)\n", appname, msg, cobol.FormatDuration(dur))  	os.Exit(0)  } @@ -50,11 +49,11 @@ func (pb *Argv) BadExit(msg string, err error) {  			// If it does, call the method to get the slice of errors.  			allerr := u.Unwrap()  			for _, e := range allerr { -				log.Info("Error:", e) +				fmt.Printf("Error: (%v)\n", e)  			}  		} else {  			// If it's not a joined error, you can fall back to the single-unwrap loop. -			log.Info("Error:", err) +			fmt.Printf("Error: (%v)\n", u)  		}  	} @@ -65,7 +64,7 @@ func (pb *Argv) BadExit(msg string, err error) {  	} else {  		appname = pb.AppInfo.APPNAME  	} -	log.Infof("%s error: %s (%s)\n", appname, msg, cobol.FormatDuration(dur)) +	fmt.Printf("%s error: %s (%s)\n", appname, msg, cobol.FormatDuration(dur))  	os.Exit(1)  } @@ -88,7 +87,7 @@ func ExitWatchdog() {  			return  		case t := <-dog.C:  			_ = t -			log.Info("argv.Exit() watchdog: stalled in", me.pb.AppInfo.APPNAME+".Exit()") +			fmt.Println("argv.Exit() watchdog: stalled in", me.pb.AppInfo.APPNAME+".Exit()")  			// h.Scan()  		}  	} @@ -1,10 +1,10 @@  package argvpb  import ( +	"fmt"  	"os"  	"go.wit.com/lib/cobol" -	"go.wit.com/log"  )  // this has been deprecated @@ -28,13 +28,13 @@ func (g *GuiPrep) Start() error {  // provides a runtime warning to the user that the app was compiled but lacks working features  func workInProgress() {  	s := "Mon Oct 13 10:48:16 CDT 2025" -	log.Info(cobol.Time(s) + ": " + os.Args[0] + ": argv features are disabled") -	log.Info(cobol.Time(s) + ": argv features are under active development") -	log.Info(cobol.Time(s) + ":") -	log.Info(cobol.Time(s) + ": argv Gui() support has been moved to go.wit.com/lib/fhelp") -	log.Info(cobol.Time(s) + ": Change your code. Example code is here:") -	log.Info(cobol.Time(s) + ": go.wit.com/apps/forge/argv.go") -	log.Info(cobol.Time(s) + ": go.wit.com/apps/forge/main.go") -	log.Info(cobol.Time(s) + ":") +	fmt.Println(cobol.Time(s) + ": " + os.Args[0] + ": argv features are disabled") +	fmt.Println(cobol.Time(s) + ": argv features are under active development") +	fmt.Println(cobol.Time(s) + ":") +	fmt.Println(cobol.Time(s) + ": argv Gui() support has been moved to go.wit.com/lib/fhelp") +	fmt.Println(cobol.Time(s) + ": Change your code. Example code is here:") +	fmt.Println(cobol.Time(s) + ": go.wit.com/apps/forge/argv.go") +	fmt.Println(cobol.Time(s) + ": go.wit.com/apps/forge/main.go") +	fmt.Println(cobol.Time(s) + ":")  	// panic("deprecated")  } @@ -1,10 +1,10 @@  package argvpb  import ( +	"fmt"  	"time"  	"go.wit.com/lib/cobol" -	"go.wit.com/log"  )  // gets APPNAME, BUILDTIME and VERSION from the application @@ -26,10 +26,10 @@ func initAppname() {  	} else if err == nil {  		newtime := BUILDTIME.Add(-36 * time.Hour)  		app.BUILDTIME = cobol.Time(BUILDTIME) -		log.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, newtime, app.BUILDTIME) +		fmt.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, newtime, app.BUILDTIME)  	} else {  		app.BUILDTIME = anyString -		log.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, BUILDTIME, app.BUILDTIME) +		fmt.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, BUILDTIME, app.BUILDTIME)  	}  	me.pb.AppInfo = app  } diff --git a/makeAutocompleteFiles.bash.go b/makeAutocompleteFiles.bash.go index 1a4158c..f0cc953 100644 --- a/makeAutocompleteFiles.bash.go +++ b/makeAutocompleteFiles.bash.go @@ -10,7 +10,6 @@ import (  	"strings"  	"go.wit.com/lib/config" -	"go.wit.com/log"  )  func MakeBashCompleteFiles(argname string) { @@ -18,12 +17,12 @@ func MakeBashCompleteFiles(argname string) {  	homeDir, err := os.UserHomeDir()  	if err != nil { -		log.Printf("# %v\n", err) +		fmt.Printf("# %v\n", err)  		os.Exit(0)  	}  	filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname)  	if config.Exists(filename) { -		log.Fprintln(os.Stderr, "# file already exists", filename) +		fmt.Fprintln(os.Stderr, "# file already exists", filename)  		// os.Exit(0)  	}  	basedir, _ := filepath.Split(filename) @@ -35,7 +34,7 @@ func MakeBashCompleteFiles(argname string) {  		f.Write([]byte(makeBashCompletionText2(argname)))  		f.Close()  	} else { -		log.Fprintln(os.Stderr, "# open file error", filename, err) +		fmt.Fprintln(os.Stderr, "# open file error", filename, err)  	}  } diff --git a/makeAutocompleteFiles.zsh.go b/makeAutocompleteFiles.zsh.go index 98e4647..c8bbf69 100644 --- a/makeAutocompleteFiles.zsh.go +++ b/makeAutocompleteFiles.zsh.go @@ -1,11 +1,11 @@  package argvpb -import "go.wit.com/log" +import "fmt"  // makes the autocomplete files for 'zsh'  func MakeZshCompleteFiles(argname string) { -	log.Info("todo: zsh") +	fmt.Println("todo: zsh")  }  /* @@ -1,6 +1,6 @@  package argvpb -import "go.wit.com/log" +import "fmt"  // these are things I'm not sure about doing  // or haven't figured out what to do with @@ -16,8 +16,8 @@ type ArgsBash struct {  // maybe this is a good idea, maybe not  func (pb *Argv) Gui() bool { -	log.Printf("CUR pb: %v\n", pb) -	log.Info("CUR ARGV:", pb.Real) +	fmt.Printf("CUR pb: %v\n", pb) +	fmt.Println("CUR ARGV:", pb.Real)  	if "gui" == pb.GetCmd() {  		return true  	} @@ -25,5 +25,5 @@ func (pb *Argv) Gui() bool {  }  func (pb *Argv) Dump() { -	log.Printf("CUR pb: %v\n", pb) +	fmt.Printf("CUR pb: %v\n", pb)  } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 94fb38c..d9ef386 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -13,7 +13,6 @@ import (  	"go.wit.com/lib/ENV"  	"go.wit.com/lib/cobol"  	"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"  ) @@ -56,9 +55,9 @@ func Autocomplete(dest any) *Argv {  	if me.guiFunc != nil {  		// register gui args  		me.guiFunc() -		// log.Info("gui init") +		// fmt.Println("gui init")  	} else { -		// log.Info("no gui init") +		// fmt.Println("no gui init")  	}  	// user is trying to setup bash or zsh autocomplete @@ -144,18 +143,38 @@ func Autocomplete(dest any) *Argv {  	if strings.HasPrefix(me.pb.Partial, "--argv") {  		me.pb.SendString("--argvdebug --argvhelp") -		os.Exit(0) +		me.pb.Stderr += fmt.Sprintln("argv override") +		me.debug = true +		me.pb.PrintStderrExit() +	} + +	// highjack "--gui" +	if len(me.pb.Real) > 1 { +		lastarg := me.pb.Real[len(me.pb.Real)-1] +		// this is a work in progress +		if lastarg == "--gui" { +			me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real) +			me.pb.PrintStderr() +			me.pb.SendString("andlabs gogui") +			os.Exit(0) +		} else { +			// me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", me.last, key, val) +		}  	}  	// use go-args to parse the structs so we can use them here  	// me.pp, err = arg.ParseFlags(flags, dest)  	if me.parseFlagsFunc == nil { -		panic("argv.parseFlags() is nil") +		me.pb.Stderr += fmt.Sprintln("argv.parseFlags() is nil") +		me.debug = true +		me.pb.PrintStderrExit()  	}  	if err := me.parseFlagsFunc(flags); err != nil { -		log.Info("application parseFlags() err", err) -		panic("argv.parseFlags() err. probably cmd doesn't really exist in struct") +		me.pb.Stderr += fmt.Sprintf("application parseFlags() err(%v)\n", err) +		me.pb.Stderr += fmt.Sprintln("argv.parseFlags() err. probably cmd doesn't really exist in struct") +		me.debug = true +		me.pb.PrintStderrExit()  	}  	if len(flags) == 0 { @@ -171,19 +190,10 @@ func Autocomplete(dest any) *Argv {  	all.Clone(me.pb)  	errors.Join(err, all.Save()) -	lastarg := me.pb.Real[len(me.pb.Real)-1] -	// this is a work in progress -	if lastarg == "--gui" { -		me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real) -		me.pb.SendString("andlabs gogui") -		os.Exit(0) -	} else { -		// me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", me.last, key, val) -	} -  	if me.pb.Fast {  		if me.last.Fast { -			os.Exit(0) +			me.debug = true +			me.pb.PrintStderr()  		} else {  			// this means the user is pressing tab. no longer doing stderr  			if me.pb.GetCmd() == "" {  | 
