summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-26 10:48:41 -0500
committerJeff Carr <[email protected]>2025-10-26 10:48:41 -0500
commit51027a1b04b3da1a81d617d16a07ac1242d90a81 (patch)
treececc3b9d3d1c2e9b6285117bb5ae01827b30fd22
parent0653bd60ce9276ad6245b25c60f37aefd0d1408a (diff)
update for new argvpb changes
-rw-r--r--Makefile17
-rw-r--r--argv.custom.go29
-rw-r--r--argv.go (renamed from argv.struct.go)0
-rw-r--r--complete.go42
-rw-r--r--generate.go9
-rw-r--r--main.go3
-rw-r--r--parseArgvStruct.go4
7 files changed, 63 insertions, 41 deletions
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.struct.go b/argv.go
index 4a1db02..4a1db02 100644
--- a/argv.struct.go
+++ b/argv.go
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
}
}