From 51027a1b04b3da1a81d617d16a07ac1242d90a81 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 26 Oct 2025 10:48:41 -0500 Subject: update for new argvpb changes --- Makefile | 17 ++++++++++++++++- argv.custom.go | 29 ----------------------------- argv.go | 15 +++++++++++++++ argv.struct.go | 15 --------------- complete.go | 42 ++++++++++++++++++++++++++++++++++++++++++ generate.go | 9 --------- main.go | 3 +++ parseArgvStruct.go | 4 ++-- 8 files changed, 78 insertions(+), 56 deletions(-) delete mode 100644 argv.custom.go create mode 100644 argv.go delete mode 100644 argv.struct.go create mode 100644 complete.go delete mode 100644 generate.go diff --git a/Makefile b/Makefile index ab46d8f..4a031b7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,19 @@ -all: generate vet +VERSION = $(shell git describe --tags) +BUILDTIME = $(shell date +%s) + +all: install + +go-build: goimports + GO111MODULE=off go build \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" + +install: goimports + GO111MODULE=off go install \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" + +install-verbose: goimports + GO111MODULE=off go install -v -x \ + -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" generate: clean go mod init diff --git a/argv.custom.go b/argv.custom.go deleted file mode 100644 index c6774a5..0000000 --- a/argv.custom.go +++ /dev/null @@ -1,29 +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 ( - "os" - - "go.wit.com/lib/protobuf/argvpb" -) - -// sent via -ldflags -var VERSION string -var BUILDTIME string - -// used for shell auto completion -var APPNAME string = "mirrors" // todo: get this from $0 - -// sends the strings to bash or zsh that will be your options -func (a args) SendCompletionStrings(pb *argvpb.Argv) { - base := []string{"--dry-run", "--force", "incoming", "walk", "list", "everything", "verify", "newest", "--create", "--verbose", "release"} - - if pb.GetCmd() == "" { - pb.SendStrings(base) - } else { - pb.SubCommand(pb.Goargs...) - } - os.Exit(0) -} diff --git a/argv.go b/argv.go new file mode 100644 index 0000000..4a1db02 --- /dev/null +++ b/argv.go @@ -0,0 +1,15 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +var argv args + +type args struct { + Test *EmptyCmd `arg:"subcommand:test" help:"test"` + Verbose bool `arg:"--verbose" help:"be loud about it"` + Force bool `arg:"--force" help:"rebuild everything"` +} + +type EmptyCmd struct { +} diff --git a/argv.struct.go b/argv.struct.go deleted file mode 100644 index 4a1db02..0000000 --- a/argv.struct.go +++ /dev/null @@ -1,15 +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 - -var argv args - -type args struct { - Test *EmptyCmd `arg:"subcommand:test" help:"test"` - Verbose bool `arg:"--verbose" help:"be loud about it"` - Force bool `arg:"--force" help:"rebuild everything"` -} - -type EmptyCmd struct { -} diff --git a/complete.go b/complete.go new file mode 100644 index 0000000..b7c7a47 --- /dev/null +++ b/complete.go @@ -0,0 +1,42 @@ +// 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" + "strings" + + "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/protobuf/argvpb" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +// used for shell auto completion +var APPNAME string = "mirrors" // todo: get this from $0 + +func (args) MustParse() error { + me.pp = arg.MustParse(&argv) + return nil +} + +// sends the strings to bash or zsh that will be your options +func (a args) DoAutoComplete() error { + if argvpb.PB.GetCmd() == "" { + matches := []string{"--dry-run", "--force", "incoming", "walk", "list", "everything", "verify", "newest", "--create", "--verbose", "release"} + fmt.Fprintf(argvpb.Stdout, " %s", strings.Join(matches, " ")) + return nil + } + var err error + if me.pp == nil { + me.pp, err = arg.ParseFlagsArgv(&argv) + if err != nil { + return err + } + } + err = me.pp.WriteHelpForAutocomplete(argvpb.PB.Partial, argvpb.PB.Real...) + return err +} diff --git a/generate.go b/generate.go deleted file mode 100644 index 91503d8..0000000 --- a/generate.go +++ /dev/null @@ -1,9 +0,0 @@ -package golib - -// NOTE: it would be helpful if go.mod doesn't exist, that go generate -// would automatically run go mod init and go mod tidy -// and allow directives to 'go get go.wit.com/apps/autogenpb' -// then this process could be fully automated -// -//go:generate make go-generate -//go:generate bash -c "goimports -w *.go" diff --git a/main.go b/main.go index 70d95a6..4637ad2 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,8 @@ package main import ( "embed" + + "go.wit.com/lib/protobuf/argvpb" ) //go:embed resources/* @@ -9,6 +11,7 @@ var resources embed.FS func main() { me = new(mainType) + argvpb.Init(&argv, APPNAME, BUILDTIME, VERSION) // adds shell auto-complete parseArgvStruct() } diff --git a/parseArgvStruct.go b/parseArgvStruct.go index d8ef1ac..83954e1 100644 --- a/parseArgvStruct.go +++ b/parseArgvStruct.go @@ -9,7 +9,7 @@ import ( "go.wit.com/log" ) -func parseArgvStruct() (*argvpb.Argv, error) { +func parseArgvStruct() (*argvpb.Argvs, error) { file, err := os.Open("argv.struct.go") if err != nil { return nil, err @@ -24,7 +24,7 @@ func parseArgvStruct() (*argvpb.Argv, error) { log.Info("LINE:", line) parts := strings.Fields(line) if len(parts) > 0 { - pb.Fast = true + // pb.Fast = true } } -- cgit v1.2.3