summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto.Print.go2
-rw-r--r--dryrun.go7
-rw-r--r--exit.go10
-rw-r--r--interface.go16
-rw-r--r--parseArgv.go2
-rw-r--r--sendStrings.go24
-rw-r--r--structs.go5
-rw-r--r--theMagicOfAutocomplete.go36
-rw-r--r--version.go4
9 files changed, 57 insertions, 49 deletions
diff --git a/auto.Print.go b/auto.Print.go
index 0fcdd8a..377d921 100644
--- a/auto.Print.go
+++ b/auto.Print.go
@@ -56,5 +56,5 @@ func (all *Autos) PrintHistory() {
// todo: fix this
func (pb *Auto) WriteHelp() {
- myAuto.pp.WriteHelp(os.Stdout)
+ me.pp.WriteHelp(os.Stdout)
}
diff --git a/dryrun.go b/dryrun.go
new file mode 100644
index 0000000..e8e36bd
--- /dev/null
+++ b/dryrun.go
@@ -0,0 +1,7 @@
+package prep
+
+// initializes logging and command line options
+
+func DryRun() bool {
+ return false
+}
diff --git a/exit.go b/exit.go
index a9deec7..393ddec 100644
--- a/exit.go
+++ b/exit.go
@@ -17,8 +17,8 @@ import (
func (pb *Auto) GoodExit(msg string) {
go ExitWatchdog()
- if myAuto.appExit != nil {
- myAuto.appExit()
+ if me.appExit != nil {
+ me.appExit()
}
dur := time.Since(pb.Ctime.AsTime())
log.Infof("%s: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur))
@@ -27,8 +27,8 @@ func (pb *Auto) GoodExit(msg string) {
func (pb *Auto) BadExit(msg string, err error) {
go ExitWatchdog()
- if myAuto.appExit != nil {
- myAuto.appExit()
+ if me.appExit != nil {
+ me.appExit()
}
// print out errors. this handles wrapped errors which is a useful
if err != nil {
@@ -68,7 +68,7 @@ func ExitWatchdog() {
return
case t := <-dog.C:
_ = t
- log.Info("argv.Exit() watchdog: stalled in", myAuto.ARGNAME+".Exit()")
+ log.Info("argv.Exit() watchdog: stalled in", me.ARGNAME+".Exit()")
// h.Scan()
}
}
diff --git a/interface.go b/interface.go
index 24f61c3..0a8b784 100644
--- a/interface.go
+++ b/interface.go
@@ -47,42 +47,42 @@ type exitI interface {
// Described is the interface that the destination struct should implement to
func findAppInfo(tmp interface{}) {
if tmp, ok := tmp.(appnameI); ok {
- myAuto.ARGNAME = tmp.Appname()
+ me.ARGNAME = tmp.Appname()
} else {
panic("you must define in your app the function: (argv) func Appname() string")
}
if tmp, ok := tmp.(buildtimeI); ok {
- myAuto.buildtime = tmp.Buildtime
- myAuto.BUILDTIME, myAuto.VERSION = myAuto.buildtime()
+ me.buildtime = tmp.Buildtime
+ me.BUILDTIME, me.VERSION = me.buildtime()
} else {
// panic("your app is missing (argv) func Buildtime() (string, string)")
}
if tmp, ok := tmp.(examplesI); ok {
- myAuto.examples = tmp.Examples
+ me.examples = tmp.Examples
}
if tmp, ok := tmp.(guiI); ok {
- myAuto.guiFunc = tmp.ArgvGui
+ me.guiFunc = tmp.ArgvGui
} else {
// panic("you must add this function to argv.go: (argv) func ArgvGui() error")
}
if tmp, ok := tmp.(autoFuncI); ok {
- myAuto.autoFunc = tmp.DoAutoComplete
+ me.autoFunc = tmp.DoAutoComplete
} else {
// panic("you need to make the function argv.DoAutoComplete()")
}
if tmp, ok := tmp.(sendCompletionStringsI); ok {
- myAuto.autoFunc = tmp.SendCompletionStrings
+ me.autoFunc = tmp.SendCompletionStrings
} else {
// panic("you need to make the function argv.DoAutoComplete()")
}
if tmp, ok := tmp.(exitI); ok {
- myAuto.appExit = tmp.Exit
+ me.appExit = tmp.Exit
} else {
// panic("you need to make the function argv.Exit()")
}
diff --git a/parseArgv.go b/parseArgv.go
index d16c745..f0103f0 100644
--- a/parseArgv.go
+++ b/parseArgv.go
@@ -66,7 +66,7 @@ func parseArgv(argname string) *Auto {
// print the version and exit
if len(os.Args) > 1 && os.Args[1] == "--version" {
- if myAuto.buildtime != nil {
+ if me.buildtime != nil {
// if binary defined buildtime() then process standard version output here
doVersion(pb)
os.Exit(0)
diff --git a/sendStrings.go b/sendStrings.go
index 78b7a6c..98ab7fa 100644
--- a/sendStrings.go
+++ b/sendStrings.go
@@ -36,17 +36,17 @@ func (pb *Auto) SendStrings(parts []string) {
// 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")
+ if me.pp == nil {
+ pb.Debugf("me.pp == nil")
} else {
- pb.Debugf("myAuto.pp != nil")
+ pb.Debugf("me.pp != nil")
if pb.Fast {
// this means the user is pressing tab. no longer doing stderr
} else {
if pb.Cmd == "" {
- myAuto.pp.WriteHelp(os.Stderr)
+ me.pp.WriteHelp(os.Stderr)
} else {
- myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd)
+ me.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd)
}
}
}
@@ -86,7 +86,7 @@ func (pb *Auto) GenerateSubCommandStrings(cmd ...string) {
func (pb *Auto) SubCommand(cmd ...string) {
partial := strings.Trim(pb.Partial, "'")
if pb.Debug {
- if myAuto.examples == nil {
+ if me.examples == nil {
pb.Debugf("WRITE DEBUG: argv.Examples() not defined")
// log.Fprintf(os.Stderr, "\n")
// log.Fprintf(os.Stderr, "examples was nil\n")
@@ -95,18 +95,18 @@ func (pb *Auto) SubCommand(cmd ...string) {
log.Fprintf(os.Stderr, "\n")
log.Fprintf(os.Stderr, "\n")
log.Fprintf(os.Stderr, "Examples:\n")
- for _, line := range strings.Split(myAuto.examples(), "\n") {
+ for _, line := range strings.Split(me.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)
+ me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...)
+ // me.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd)
+ // me.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)
+ me.pp.WriteHelpForAutocomplete(f, os.Stdout, partial, cmd...)
+ // me.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
}
os.Exit(0)
}
diff --git a/structs.go b/structs.go
index 052c7ad..31b7cc4 100644
--- a/structs.go
+++ b/structs.go
@@ -19,7 +19,7 @@ type ArgsBash struct {
}
// try this struct out (?)
-var myAuto *AutoArgs
+var me *AutoArgs
// this is a work in progress
type AutoArgs struct {
@@ -33,6 +33,7 @@ type AutoArgs struct {
autoFunc func(*Auto) // also a function for autocomplete
guiFunc func() error // enables Gui functions
err error // store any errors from argv
+ pb *Auto
ARGNAME string // a good way to track the name of the binary ?
VERSION string
@@ -55,5 +56,5 @@ func GetLast(cur string, argv []string) string {
// returns the name of the executable registered for shell autocomplete
func AppName() string {
- return myAuto.ARGNAME
+ return me.ARGNAME
}
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 1eeedd1..648e28f 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -17,28 +17,28 @@ import (
// TODO: rename 'all' to 'pb' and 'pb' to 'pbnew' or 'pbcur'
func Autocomplete(dest any) *Auto {
- myAuto = new(AutoArgs) // todo: redo this
- findAppInfo(dest) // parses back to main() for argv info
+ me = new(AutoArgs) // todo: redo this
+ findAppInfo(dest) // parses back to main() for argv info
- if myAuto.guiFunc != nil {
+ if me.guiFunc != nil {
// register gui args
- myAuto.guiFunc()
+ me.guiFunc()
// log.Info("gui init")
} else {
// log.Info("no gui init")
}
// parses os.Args into a protobuf
- pb := parseArgv(myAuto.ARGNAME)
+ pb := parseArgv(me.ARGNAME)
// the argv history
all := NewAutos()
// initializes the application config file
- config.Init(myAuto.ARGNAME, myAuto.VERSION, myAuto.BUILDTIME, pb.Argv)
+ config.Init(me.ARGNAME, me.VERSION, me.BUILDTIME, pb.Argv)
// loads the autocomplete history file
- err := config.LoadCache(all, "argv", myAuto.ARGNAME) //
+ err := config.LoadCache(all, "argv", me.ARGNAME) //
if err != nil {
// there is no history.
// todo: initialize the history file
@@ -56,7 +56,7 @@ func Autocomplete(dest any) *Auto {
// --bash or --zsh is the first os.Args
if pb.SetupAuto {
// --bash was passed. try to configure bash-completion
- MakeAutocompleteFiles(myAuto.ARGNAME)
+ MakeAutocompleteFiles(me.ARGNAME)
// never forget to run this our you will hate yourself and the choices you have made
os.Exit(0)
}
@@ -67,8 +67,8 @@ func Autocomplete(dest any) *Auto {
all.Clone(pb)
errors.Join(err, all.Save())
- myAuto.pp = arg.MustParse(dest)
- myAuto.err = err
+ me.pp = arg.MustParse(dest)
+ me.err = err
return pb
}
@@ -129,7 +129,7 @@ func Autocomplete(dest any) *Auto {
}
// use go-args to parse the structs so we can use them here
- myAuto.pp, err = arg.ParseFlags(flags, dest)
+ me.pp, err = arg.ParseFlags(flags, dest)
if len(flags) == 0 {
// error is normal if there are no command line args
} else {
@@ -139,10 +139,10 @@ func Autocomplete(dest any) *Auto {
}
}
- if myAuto.pp == nil {
- pb.Debugf("DEBUG: myAuto.pp == nil after ParseFlags()")
+ if me.pp == nil {
+ pb.Debugf("DEBUG: me.pp == nil after ParseFlags()")
} else {
- // pb.Debugf("DEBUG: myAuto.pp is ok after ParseFlags()")
+ // pb.Debugf("DEBUG: me.pp is ok after ParseFlags()")
}
// save now. this is near the end probably
@@ -164,18 +164,18 @@ func Autocomplete(dest any) *Auto {
} else {
// this means the user is pressing tab. no longer doing stderr
if pb.Cmd == "" {
- myAuto.pp.WriteHelp(os.Stderr)
+ me.pp.WriteHelp(os.Stderr)
} else {
- myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd)
+ me.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd)
}
}
} else {
}
- if myAuto.autoFunc == nil {
+ if me.autoFunc == nil {
pb.SubCommand(pb.Argv...)
} else {
- myAuto.autoFunc(pb) // run the autocomplete function the user made for their application
+ me.autoFunc(pb) // run the autocomplete function the user made for their application
}
if pb.Debug {
// TODO:
diff --git a/version.go b/version.go
index 0b923e5..b4f26fe 100644
--- a/version.go
+++ b/version.go
@@ -20,10 +20,10 @@ func doVersion(pb *Auto) {
}
func (pb *Auto) getVersion() string {
- if myAuto.buildtime == nil {
+ if me.buildtime == nil {
return "app doesn't have argv.BuildVersion()"
}
- BUILDTIME, VERSION := myAuto.buildtime()
+ BUILDTIME, VERSION := me.buildtime()
return fmt.Sprintf("%s %s Built on %s", pb.Argname, VERSION, cobol.Time(BUILDTIME))
}