summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-24 02:36:45 -0500
committerJeff Carr <[email protected]>2025-10-24 02:36:45 -0500
commit41cf7c3c4ca2fbfca7f9c2328e6f4e0ac34661d9 (patch)
tree69c6e3329cd6f14b987fb5403206e9b7773d32b0
parent3d0d7fa233f712c1c57b3b3092dece6f746f0f03 (diff)
try setting ENV globals for "--" args
-rw-r--r--argv.parseOsArgs.go5
-rw-r--r--theMagicOfAutocomplete.go10
2 files changed, 13 insertions, 2 deletions
diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go
index 8623138..70231ef 100644
--- a/argv.parseOsArgs.go
+++ b/argv.parseOsArgs.go
@@ -10,7 +10,7 @@ import (
"go.wit.com/log"
)
-func (pb *Argv) parseArgv() {
+func (pb *Argv) parseOsArgs() {
// this shouldn't really happen. OS/POSIX error?
if len(os.Args) == 0 {
// fmt.Fprintf(os.Stderr, "what OS is this?\n")
@@ -71,6 +71,9 @@ func (pb *Argv) parseArgv() {
if os.Args[1] != "--auto-complete" {
// if the first arg is not --auto-complete, then don't go any farther
for _, s := range os.Args[1:] {
+ pb.Real = append(pb.Real, s)
+ }
+ for _, s := range os.Args[1:] {
if strings.HasPrefix(s, "-") {
// option is something like --verbose
// skip these. they are not subcommands
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 3bc32f0..3f2311f 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -5,6 +5,7 @@ package argvpb
import (
"errors"
+ "fmt"
"os"
"strings"
"time"
@@ -34,7 +35,7 @@ func Autocomplete(dest any) *Argv {
initAppname()
// parses os.Args into the protobuf
- me.pb.parseArgv()
+ me.pb.parseOsArgs()
// initializes the lib/ENV library
ENV.Init(me.pb.AppInfo.APPNAME, me.pb.AppInfo.VERSION, cobol.Time(me.pb.AppInfo.BUILDTIME), me.pb.Real, GoodExit, BadExit)
@@ -69,6 +70,13 @@ func Autocomplete(dest any) *Argv {
os.Exit(0)
}
+ ENV.SetGlobal("argv", "real", fmt.Sprintf("%v", me.pb.Real))
+ for _, a := range me.pb.Real {
+ if strings.HasPrefix(a, "--") {
+ ENV.SetGlobal("argv", a, "true")
+ }
+ }
+
// not autocompleting. return go-arg & the application
if !me.pb.IsAuto {
// save the pb & history