diff options
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | argv.go | 36 | ||||
| -rwxr-xr-x | build | 3 | ||||
| -rw-r--r-- | main.go | 22 | ||||
| -rw-r--r-- | structs.go | 4 |
5 files changed, 46 insertions, 25 deletions
@@ -1,7 +1,7 @@ .PHONY: build VERSION = $(shell git describe --tags) -BUILDTIME = $(shell date +%Y.%m.%d_%H%M) +BUILDTIME = $(shell date +%s) # create the go.mod and go.sum if this is a brand new repo # REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi) @@ -9,13 +9,13 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= all: build ./zood --version - ./zood test + ./zood status build: goimports 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 -v -x \ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" @@ -9,14 +9,17 @@ package main */ import ( - "go.wit.com/dev/alexflint/arg" + "os" + + "go.wit.com/lib/gui/prep" "go.wit.com/log" ) var argv args type args struct { - Test *EmptyCmd `arg:"subcommand:test" help:"New to forge? This is for you.'"` + Status *EmptyCmd `arg:"subcommand:status" help:"should display something"` + Test *EmptyCmd `arg:"subcommand:test" help:"test stuff"` Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` Port int `arg:"--port" default:"2521" help:"port to run on"` URL string `arg:"--url" help:"url to use"` @@ -25,14 +28,6 @@ type args struct { type EmptyCmd struct { } -func (args) Version() string { - return "zood " + VERSION + " Built on: " + BUILDTIME -} - -func init() { - arg.MustParse(&argv) -} - func (a args) Description() string { return ` this daemon talks to zookeeper @@ -53,3 +48,24 @@ func init() { PING = log.NewFlag("PING", false, full, short, "show pings to the zookeeper") WARN = log.NewFlag("WARN", true, full, short, "bad things") } + +func (args) Version() string { + return ARGNAME + " " + VERSION + " Built on " + BUILDTIME +} + +func (args) Buildtime() (string, string) { + return BUILDTIME, VERSION +} + +func (args) Appname() string { + return ARGNAME +} + +func (a args) DoAutoComplete(pb *prep.Auto) { + if pb.Cmd == "" { + pb.Autocomplete3([]string{"status", "test", "--version", "--daemon"}) + } else { + pb.SubCommand(pb.Goargs...) + } + os.Exit(0) +} @@ -4,5 +4,8 @@ mkdir -p files/lib/systemd/system/ cp zood.service files/lib/systemd/system/ +mkdir -p files/usr/share/bash-completion/completions/ +zood --bash > files/usr/share/bash-completion/completions/forge + mkdir -p files/usr/lib/zood/ cp Makefile.help files/usr/lib/zood/Makefile @@ -9,26 +9,25 @@ import ( "os" "time" - "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/gui/prep" "go.wit.com/lib/hostname" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) +// sent via -ldflags var VERSION string var BUILDTIME string +// used for shell auto completion +var ARGNAME string = "zood" + //go:embed resources/* var resources embed.FS func main() { me = new(zoodStruct) - me.pp = arg.MustParse(&argv) - - if me.pp == nil { - me.pp.WriteHelp(os.Stdout) - os.Exit(0) - } + me.sh = prep.Bash(&argv) // adds shell auto complete to go-args if argv.Daemon { // turn off timestamps for STDOUT (systemd adds them) @@ -36,14 +35,17 @@ func main() { me.machine, me.fullpath = zoopb.InitDaemon() } else { me.machine, me.fullpath = zoopb.InitMachine() + } + if argv.Status != nil { + log.Info("todo: show status here") + me.sh.GoodExit("says hi") } if err := testZoo(); err != nil { - log.Info("FAILED TO CONNECT TO ZOOKEEPER: ", err) - log.Info("sleeping for 3 minutes") + log.Info("failed to connect. sleeping for 3 minutes") time.Sleep(3 * time.Minute) - os.Exit(0) + me.sh.BadExit("failed to connect to zookeeper", err) } me.pollDelay = 3 * time.Second me.failcountmax = 20 // die every minute if zookeeper can't be found @@ -6,7 +6,7 @@ package main import ( "time" - "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/zoopb" ) @@ -14,6 +14,7 @@ var me *zoodStruct // this app's variables type zoodStruct struct { + sh *prep.Auto // shell autocomplete urlbase string // the dns name for the zookeeper hostname string // my hostname pollDelay time.Duration // how often to report our status @@ -22,5 +23,4 @@ type zoodStruct struct { failcount int // how many times we've failed to contact the zookeeper failcountmax int // after this, exit and let systemd restart the daemon fullpath string // where to save the machine PB file - pp *arg.Parser // from go-args } |
