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.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
all: goimports gocui-debugging
# ./zookeeper
all: build
./zookeeper list
vet:
@GO111MODULE=off go vet
@ -20,6 +20,9 @@ nogui:
gocui: build
./zookeeper --gui gocui
gocui-5000: build
./zookeeper --gui gocui --port 5000
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 >/tmp/forge.log 2>&1

52
argv.go
View File

@ -9,16 +9,27 @@ package main
*/
import (
"fmt"
"os"
"go.wit.com/log"
)
var argv args
type args struct {
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"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"`
List *EmptyCmd `arg:"subcommand:list" help:"list the machines in your zoo"`
Upgrade *EmptyCmd `arg:"subcommand:upgrade" help:"upgrade the machines"`
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 {
@ -51,3 +62,36 @@ func init() {
ZOOD = log.NewFlag("ZOOD", false, full, short, "show reporting from zood")
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"
"go.wit.com/gui"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
@ -38,8 +39,19 @@ func refresh() {
func doGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
me.myGui.Default()
me.myGui.SetAppDefaultPlugin("gocui") // sets the default GUI plugin to use
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.Make()

28
main.go
View File

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