still working on how this should work

This commit is contained in:
Jeff Carr 2025-09-18 08:54:33 -05:00
parent fec80aca17
commit 763b1a60fc
2 changed files with 16 additions and 21 deletions

View File

@ -28,7 +28,7 @@ func doBash2(argname string) {
filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname)
if shell.Exists(filename) {
log.Println(filename, "file already exists")
os.Exit(0)
// os.Exit(0)
}
basedir, _ := filepath.Split(filename)
if !shell.IsDir(basedir) {
@ -215,7 +215,7 @@ func parseArgv(argname string) *Auto {
}
// also try to parse/send cur (?)
func Bash2(argname string, autocomplete func(*Auto)) {
func Bash2(argname string, autocomplete func(*Auto)) *Auto {
newauto := parseArgv(argname)
if newauto.SetupAuto {
// --bash was passed. try to configure bash-completion
@ -239,4 +239,5 @@ func Bash2(argname string, autocomplete func(*Auto)) {
}
arg.Register(&argBash)
return newauto
}

View File

@ -13,35 +13,32 @@ import (
"go.wit.com/log"
)
var argBash ArgsBash
/*
This struct can be used with the go-arg package. These
are the generic default command line arguments for the 'GUI' package
*/
var argBash ArgsBash
type ArgsBash struct {
Bash bool `arg:"--bash" help:"generate bash completion"`
}
var myBash *BashAuto
// try this struct out (?)
var myAuto *AutoArgs
type BashAuto struct {
type AutoArgs struct {
id int // should be unique
hidden bool // don't update the toolkits when it's hidden
Auto func([]string)
appName string // a good way to track the name of the binary ?
appName string // a good way to track the name of the binary ?
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
}
/*
func dumpjunk() {
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, os.Args)
os.Exit(0)
}
*/
// argname is the name of the executable
func Bash(argname string, autocomplete func([]string)) *BashAuto {
func Bash(argname string, autocomplete func([]string)) *AutoArgs {
myAuto = new(AutoArgs)
myAuto.appName = argname
if len(os.Args) > 1 && os.Args[1] == "--bash" {
doBash(argname)
os.Exit(0)
@ -54,11 +51,8 @@ func Bash(argname string, autocomplete func([]string)) *BashAuto {
arg.Register(&argBash)
myBash = new(BashAuto)
myBash.appName = argname
// parse go.Arg here?
return myBash
return myAuto
}
// print out auto complete debugging info
@ -84,7 +78,7 @@ func GetLast(cur string, argv []string) string {
// returns the name of the executable registered for shell autocomplete
func AppName() string {
return myBash.appName
return myAuto.appName
}
// makes a bash autocomplete file for your command