From bb99305225210181525b1482888a7bfddd9ff68e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 25 Sep 2025 01:41:05 -0500 Subject: new autocomplete method --- Makefile | 2 +- argv.go | 40 ++++++++++++---------------------------- build | 3 +++ main.go | 6 ++---- structs.go | 3 +-- 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 57ab3d1..c2eb5a9 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ build: goimports vet GO111MODULE=off go build -v -x \ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -install: +install: goimports GO111MODULE=off go install \ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" diff --git a/argv.go b/argv.go index b1f2a56..a29adb9 100644 --- a/argv.go +++ b/argv.go @@ -9,9 +9,9 @@ package main */ import ( - "fmt" "os" + "go.wit.com/lib/gui/prep" "go.wit.com/log" ) @@ -63,35 +63,19 @@ func init() { WARN = log.NewFlag("WARN", true, full, short, "bad things") } -// prints help to STDERR // TODO: move everything below this to go-args -func (args) doBashHelp() { - if argv.BashAuto[1] != "''" { - // if this is not blank, then the user has typed something - return - } - if argv.BashAuto[0] != ARGNAME { - // if this is not the name of the command, the user already started doing something - return - } - if argv.BashAuto[0] == ARGNAME { - me.pp.WriteHelp(os.Stderr) - return - } +/* + handles shell autocomplete +*/ + +func (args) Appname() string { + return ARGNAME } -func (args) DoAutoComplete(argv []string) { - switch argv[0] { - case "list": - fmt.Println("") - case "verify": - fmt.Println("on") - case "upgrade": - fmt.Println("") - default: - if argv[0] == ARGNAME { - // list the subcommands here - fmt.Println("help list") - } +func (a args) DoAutoComplete(pb *prep.Auto) { + if pb.Cmd == "" { + pb.Autocomplete3([]string{"gui", "list", "--daemon"}) + } else { + pb.SubCommand(pb.Argv...) } os.Exit(0) } diff --git a/build b/build index ca28d63..83f16a6 100755 --- a/build +++ b/build @@ -6,3 +6,6 @@ cp zookeeper.service files/lib/systemd/system/ mkdir -p files/usr/lib/zookeeper/ cp Makefile.help files/usr/lib/zookeeper/Makefile + +mkdir -p files/usr/share/bash-completion/completions/ +zookeeper --bash > files/usr/share/bash-completion/completions/zookeeper diff --git a/main.go b/main.go index a8a612d..be28e36 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "os" "time" - "go.wit.com/dev/alexflint/arg" "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/httppb" "go.wit.com/lib/protobuf/zoopb" @@ -21,9 +20,8 @@ var ARGNAME string = "zookeeper" func main() { me = new(mainType) - prep.Bash(ARGNAME, argv.DoAutoComplete) // this line should be: prep.Bash(argv) - me.myGui = prep.Gui() // prepares the GUI package for go-args - me.pp = arg.MustParse(&argv) + me.myGui = prep.Gui() // prepares the GUI package for go-args + me.auto = prep.Bash3(&argv) // add support for bash autocomplete with go-arg if argv.Daemon { // turn off timestamps for STDOUT (systemd adds them) diff --git a/structs.go b/structs.go index 136de37..2ade15a 100644 --- a/structs.go +++ b/structs.go @@ -6,7 +6,6 @@ package main import ( "time" - "go.wit.com/dev/alexflint/arg" "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/prep" @@ -17,7 +16,7 @@ var me *mainType // this app's variables type mainType struct { - pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + auto *prep.Auto // more experiments for bash handling hostname string // my fqdn dns zookeeper hostname pollDelay time.Duration // how often to report our status dog *time.Ticker // the watchdog timer -- cgit v1.2.3