new GUI codebase
This commit is contained in:
parent
f67c81d499
commit
dbcd3b5686
32
argv.go
32
argv.go
|
@ -1,6 +1,11 @@
|
|||
package main
|
||||
|
||||
import "go.wit.com/log"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
/*
|
||||
this parses the command line arguements
|
||||
|
@ -74,3 +79,28 @@ func init() {
|
|||
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
||||
EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events")
|
||||
}
|
||||
|
||||
/*
|
||||
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")
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
/*
|
||||
handles shell autocomplete
|
||||
*/
|
||||
|
||||
// used for shell auto completion
|
||||
// var ARGNAME string = "forge" // todo: get this from $0 ?
|
||||
|
||||
func deleteMatch() {
|
||||
// f := forgedb.InitSimple()
|
||||
fmt.Println("go.wit.com/lib/gui/repostatus todo: need to do this")
|
||||
}
|
||||
|
||||
func (args) doBashAuto() {
|
||||
argv.doBashHelp()
|
||||
switch argv.BashAuto[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.BashAuto[0] == ARGNAME {
|
||||
// list the subcommands here
|
||||
fmt.Println("--bash list droplet")
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "")
|
||||
fmt.Fprintln(os.Stderr, "hello world")
|
||||
fmt.Fprintln(os.Stderr, "")
|
||||
}
|
||||
|
||||
// complete -F forge --bash forge
|
||||
func (args) doBash() {
|
||||
fmt.Println("# add this in your bashrc:")
|
||||
fmt.Println("")
|
||||
fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash")
|
||||
fmt.Println("#")
|
||||
fmt.Println("# todo: can this output work/parse with:")
|
||||
fmt.Println("# complete -C `" + ARGNAME + " --bash` " + ARGNAME)
|
||||
fmt.Println("")
|
||||
fmt.Println("_" + ARGNAME + "_complete()")
|
||||
fmt.Println("{")
|
||||
fmt.Println(" # sets local to this func vars")
|
||||
fmt.Println(" local cur prev all")
|
||||
fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}")
|
||||
fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}")
|
||||
fmt.Println(" all=${COMP_WORDS[@]}")
|
||||
fmt.Println("")
|
||||
fmt.Println(" # this is where we generate the go-arg output")
|
||||
fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)")
|
||||
fmt.Println("")
|
||||
fmt.Println(" # this compares the command line input from the user")
|
||||
fmt.Println(" # to whatever strings we output")
|
||||
fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS")
|
||||
fmt.Println(" return 0")
|
||||
fmt.Println("}")
|
||||
fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME)
|
||||
fmt.Println("")
|
||||
fmt.Println("# copy and paste the above into your bash shell should work")
|
||||
os.Exit(0)
|
||||
}
|
|
@ -150,10 +150,6 @@ func doLocalhostAdminGui() *adminT {
|
|||
}
|
||||
|
||||
func doAdminGui() {
|
||||
me.myGui = gui.New()
|
||||
me.myGui.InitEmbed(resources)
|
||||
me.myGui.Default()
|
||||
|
||||
// Initialize a persistent client with a custom Transport
|
||||
client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
|
@ -185,10 +181,6 @@ func doAdminGui() {
|
|||
}
|
||||
|
||||
func (admin *adminT) doAdminGui() {
|
||||
me.myGui = gui.New()
|
||||
me.myGui.InitEmbed(resources)
|
||||
me.myGui.Default()
|
||||
|
||||
// Initialize a persistent client with a custom Transport
|
||||
client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
|
@ -263,7 +255,7 @@ func (admin *adminT) doAdminGui() {
|
|||
})
|
||||
|
||||
grid.NewButton("test gui close", func() {
|
||||
me.myGui.Close()
|
||||
gui.StandardExit()
|
||||
// okExit("admin close")
|
||||
})
|
||||
|
||||
|
|
9
doGui.go
9
doGui.go
|
@ -11,7 +11,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/protobuf/virtpb"
|
||||
"go.wit.com/log"
|
||||
|
@ -25,10 +24,6 @@ func debug() {
|
|||
}
|
||||
|
||||
func doGui() {
|
||||
me.myGui = gui.New()
|
||||
me.myGui.InitEmbed(resources)
|
||||
me.myGui.Default()
|
||||
|
||||
mainWindow := gadgets.NewGenericWindow("Virtigo: (inventory your cluster)", "Local Cluster Settings")
|
||||
mainWindow.Custom = func() {
|
||||
log.Warn("Main window close")
|
||||
|
@ -36,10 +31,6 @@ func doGui() {
|
|||
}
|
||||
|
||||
drawWindow(mainWindow)
|
||||
|
||||
// sits here forever
|
||||
debug()
|
||||
|
||||
}
|
||||
|
||||
func drawWindow(win *gadgets.GenericWindow) {
|
||||
|
|
7
exit.go
7
exit.go
|
@ -6,6 +6,7 @@ package main
|
|||
import (
|
||||
"os"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
|
@ -13,13 +14,13 @@ func okExit(note string) {
|
|||
if note != "" {
|
||||
log.Info(ARGNAME, "exit:", note, "ok")
|
||||
}
|
||||
me.myGui.Close()
|
||||
gui.StandardExit()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func badExit(err error) {
|
||||
log.Info(ARGNAME, "failed: ", err)
|
||||
me.myGui.Close()
|
||||
gui.StandardExit()
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
|
@ -27,7 +28,7 @@ func exit(note string, err error) {
|
|||
if note != "" {
|
||||
log.Info(ARGNAME, "exit:", note, "ok")
|
||||
}
|
||||
me.myGui.Close()
|
||||
gui.StandardExit()
|
||||
if err == nil {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
21
main.go
21
main.go
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gui/prep"
|
||||
"go.wit.com/lib/protobuf/virtpb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
@ -26,18 +26,10 @@ var resources embed.FS
|
|||
|
||||
func main() {
|
||||
me = new(virtigoT)
|
||||
gui.InitArg()
|
||||
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 argv.Bash {
|
||||
argv.doBash()
|
||||
os.Exit(0)
|
||||
}
|
||||
if len(argv.BashAuto) != 0 {
|
||||
argv.doBashAuto()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if me.pp == nil {
|
||||
me.pp.WriteHelp(os.Stdout)
|
||||
os.Exit(0)
|
||||
|
@ -64,6 +56,8 @@ func main() {
|
|||
exit(doDroplet())
|
||||
}
|
||||
|
||||
me.myGui.Start() // loads the GUI toolkit
|
||||
|
||||
if argv.Admin {
|
||||
err := me.clusters.ConfigLoad()
|
||||
if err != nil {
|
||||
|
@ -105,7 +99,6 @@ func main() {
|
|||
okExit("")
|
||||
}
|
||||
|
||||
// sit here
|
||||
go startHTTP()
|
||||
doGui()
|
||||
doGui() // start making our forge GUI
|
||||
startHTTP() // sit here forever
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/gui/prep"
|
||||
"go.wit.com/lib/protobuf/virtpb"
|
||||
)
|
||||
|
||||
|
@ -25,7 +26,7 @@ func (b *virtigoT) Enable() {
|
|||
// this app's variables
|
||||
type virtigoT struct {
|
||||
pp *arg.Parser // go-arg parser
|
||||
myGui *gui.Node // the gui toolkit handle
|
||||
myGui *prep.GuiPrep // the gui toolkit handle
|
||||
e *virtpb.Events // virt protobuf events
|
||||
hmap map[*virtpb.Hypervisor]*HyperT // map to the local struct
|
||||
names []string // ?
|
||||
|
|
Loading…
Reference in New Issue