summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go28
-rwxr-xr-xbuild3
-rw-r--r--main.go11
-rw-r--r--structs.go3
4 files changed, 16 insertions, 29 deletions
diff --git a/argv.go b/argv.go
index 6f5af8f..17771b7 100644
--- a/argv.go
+++ b/argv.go
@@ -1,9 +1,9 @@
package main
import (
- "fmt"
"os"
+ "go.wit.com/lib/gui/prep"
"go.wit.com/log"
)
@@ -84,23 +84,15 @@ func init() {
handles shell autocomplete
*/
-func (a args) DoAutoComplete(argv []string) {
- switch argv[0] {
- case "list":
- fmt.Println("droplets hypervisors")
- case "droplet":
- fmt.Println("start stop")
- case "devel":
- fmt.Println("--force")
- case "master":
- fmt.Println("")
- case "verify":
- fmt.Println("user devel master")
- default:
- if argv[0] == ARGNAME {
- // list the subcommands here
- fmt.Println("--bash list droplet")
- }
+func (args) Appname() string {
+ return ARGNAME
+}
+
+func (a args) DoAutoComplete(pb *prep.Auto) {
+ if pb.Cmd == "" {
+ pb.Autocomplete3([]string{"--bash", "list", "droplet"})
+ } else {
+ pb.SubCommand(pb.Argv...)
}
os.Exit(0)
}
diff --git a/build b/build
index 58ef064..50afaf6 100755
--- a/build
+++ b/build
@@ -3,3 +3,6 @@
# this is the systemd control file
mkdir -p files/usr/bin/
cp ../virtigoctl/virtigoctl files/usr/bin/
+
+mkdir -p files/usr/share/bash-completion/completions/
+virtigo --bash > files/usr/share/bash-completion/completions/virtigo
diff --git a/main.go b/main.go
index 2f043be..19e27b8 100644
--- a/main.go
+++ b/main.go
@@ -9,7 +9,6 @@ import (
"path/filepath"
"github.com/google/uuid"
- "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/virtpb"
"go.wit.com/log"
@@ -26,14 +25,8 @@ var resources embed.FS
func main() {
me = new(virtigoT)
- 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)
-
- if me.pp == nil {
- me.pp.WriteHelp(os.Stdout)
- os.Exit(0)
- }
+ 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 os.Getenv("VIRTIGO_HOME") == "" {
homeDir, _ := os.UserHomeDir()
diff --git a/structs.go b/structs.go
index e493c41..056d240 100644
--- a/structs.go
+++ b/structs.go
@@ -4,7 +4,6 @@ import (
"net/url"
"time"
- "go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/prep"
@@ -25,7 +24,7 @@ func (b *virtigoT) Enable() {
// this app's variables
type virtigoT struct {
- pp *arg.Parser // go-arg parser
+ auto *prep.Auto // more experiments for bash handling
myGui *prep.GuiPrep // the gui toolkit handle
e *virtpb.Events // virt protobuf events
hmap map[*virtpb.Hypervisor]*HyperT // map to the local struct