This commit is contained in:
Jeff Carr 2025-09-08 20:41:51 -05:00
parent 0c4a91054f
commit d00e96e354
6 changed files with 86 additions and 24 deletions

View File

@ -7,8 +7,8 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi) # REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi) REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
all: goimports gocui-debugging all: build
# ./zookeeper ./zookeeper list
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet
@ -20,6 +20,9 @@ nogui:
gocui: build gocui: build
./zookeeper --gui gocui ./zookeeper --gui gocui
gocui-5000: build
./zookeeper --gui gocui --port 5000
gocui-debugging: build gocui-debugging: build
./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so ./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so
# ./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1 # ./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1

52
argv.go
View File

@ -9,16 +9,27 @@ package main
*/ */
import ( import (
"fmt"
"os"
"go.wit.com/log" "go.wit.com/log"
) )
var argv args var argv args
type args struct { type args struct {
Verbose bool `arg:"--verbose" default:"false" help:"talk more"` Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"`
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` List *EmptyCmd `arg:"subcommand:list" help:"list the machines in your zoo"`
Port int `arg:"--port" default:"8080" help:"port to run on"` Upgrade *EmptyCmd `arg:"subcommand:upgrade" help:"upgrade the machines"`
NoPort bool `arg:"--no-port" help:"don't open socket"` Verbose bool `arg:"--verbose" default:"false" help:"talk more"`
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
Port int `arg:"--port" default:"8080" help:"port to run on"`
NoPort bool `arg:"--no-port" help:"don't open socket"`
Bash bool `arg:"--bash" help:"generate bash completion"`
BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"`
}
type EmptyCmd struct {
} }
func (args) Version() string { func (args) Version() string {
@ -51,3 +62,36 @@ func init() {
ZOOD = log.NewFlag("ZOOD", false, full, short, "show reporting from zood") ZOOD = log.NewFlag("ZOOD", false, full, short, "show reporting from zood")
WARN = log.NewFlag("WARN", true, full, short, "bad things") 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
}
}
func (args) doBashAuto() {
switch argv.BashAuto[0] {
case "list":
fmt.Println("")
case "verify":
fmt.Println("on")
case "upgrade":
fmt.Println("")
default:
if argv.BashAuto[0] == ARGNAME {
// list the subcommands here
fmt.Println("help list")
}
}
os.Exit(0)
}

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
@ -38,8 +39,19 @@ func refresh() {
func doGui() { func doGui() {
me.myGui = gui.New() me.myGui = gui.New()
me.myGui.InitEmbed(resources) me.myGui.SetAppDefaultPlugin("gocui") // sets the default GUI plugin to use
me.myGui.Default() if pname, err := me.myGui.Default(); err != nil {
if !fhelp.BuildPlugin("gocui") {
log.Info("You can't run the forge GUI since the plugins did not build", pname)
okExit("")
} else {
if err := me.myGui.LoadToolkitNew("gocui"); err != nil {
log.Info("The plugins built, but still failed to load", pname)
badExit(err)
}
log.Info("The plugins built and loaded!", pname)
}
}
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)") win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
win.Make() win.Make()

28
main.go
View File

@ -4,12 +4,12 @@
package main package main
import ( import (
"embed"
"os" "os"
"time" "time"
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -17,17 +17,19 @@ import (
var VERSION string var VERSION string
var BUILDTIME string var BUILDTIME string
//go:embed resources/* var ARGNAME string = "zookeeper"
var resources embed.FS
func main() { func main() {
log.Warn("zookeeper PID:", os.Getpid(), os.Args) me = new(mainType)
var pp *arg.Parser gui.InitArg()
gui.InitArg() // include the 'gui' package command line arguements me.pp = arg.MustParse(&argv)
pp = arg.MustParse(&argv) // parse the command line
if pp == nil { if argv.Bash {
pp.WriteHelp(os.Stdout) fhelp.DoBash(ARGNAME)
os.Exit(0)
}
if len(argv.BashAuto) != 0 {
argv.doBashAuto()
os.Exit(0) os.Exit(0)
} }
@ -47,7 +49,6 @@ func main() {
log.DaemonMode(true) log.DaemonMode(true)
} }
me = new(zookeep)
me.hostname, _ = os.Hostname() me.hostname, _ = os.Hostname()
me.pollDelay = time.Hour me.pollDelay = time.Hour
me.machines = zoopb.NewMachines() me.machines = zoopb.NewMachines()
@ -55,9 +56,10 @@ func main() {
log.Warn("load config failed", err) log.Warn("load config failed", err)
os.Exit(-1) os.Exit(-1)
} }
// me.upgrade = make(map[string]bool) // used to trigger upgrade attempts if argv.List != nil {
log.Info("do list here")
// log.Sleep(3) okExit("")
}
go NewWatchdog() go NewWatchdog()
if !argv.NoPort { if !argv.NoPort {

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -6,15 +6,17 @@ package main
import ( import (
"time" "time"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
) )
var me *zookeep var me *mainType
// this app's variables // this app's variables
type zookeep struct { type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
hostname string // my fqdn dns zookeeper hostname hostname string // my fqdn dns zookeeper hostname
pollDelay time.Duration // how often to report our status pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer dog *time.Ticker // the watchdog timer