cleanups due to autocomplete support

This commit is contained in:
Jeff Carr 2025-01-07 17:17:01 -06:00
parent 5802e0f214
commit 7e47940796
5 changed files with 147 additions and 95 deletions

View File

@ -2,82 +2,30 @@ VERSION = $(shell git describe --tags)
GUIVERSION = $(shell git describe --tags) GUIVERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d) BUILDTIME = $(shell date +%Y.%m.%d)
all: go-build all: install
@echo "make debian-dry-run # shows what could be packaged"
@echo "make debian-build # make .deb files for versions that are missing"
@echo "make test-build # test build everything"
@echo "make make-install # run 'make install' in each app repo to copy to ~/go/bin"
@echo "make list # --list: list packaged apps in the wit repo"
@echo "make update # --update: run apt update and apt install on all packages"
@echo "make repomap # parse the go.wit.com repomap"
go-build: goimports go-build: goimports
GO111MODULE=off go build \ GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -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}"
vet: vet:
GO111MODULE=off go vet GO111MODULE=off go vet
only-me: go-build
./wit-test --only-me
stderr: go-build stderr: go-build
echo "writing to /tmp/wit-test.log" echo "writing to /tmp/wit-test.log"
./wit-test >/tmp/wit-test.log 2>&1 ./wit-test >/tmp/wit-test.log 2>&1
goimports: goimports:
reset
goimports -w *.go goimports -w *.go
# // to globally reset paths: # // to globally reset paths:
# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go # // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go
gocui: go-build clean:
./wit-test --gui gocui >/tmp/wit-test.log 2>&1 rm -f go.*
install: goimports
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
check-git-clean: check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
list: go-build
./wit-test --no-gui --list
pull: go-build
./wit-test --git-pull
update: go-build
./wit-test --apt-update --dry-run
force-build: go-build
./wit-test --force
make-install: install
wit-test --no-gui --make-install
forge --find-private
test-build: go-build
./wit-test --test-build
make-install-dry-run: go-build
./wit-test --no-gui --make-install --dry-run
protobuf:
go-clone go.wit.com/apps/go-clone
debian-dry-run: go-build
./wit-test --no-gui --dry-run --debian
debian-build: go-build
./wit-test --no-gui --debian
do-aptly
repomap: go-build
./wit-test --no-gui --repomap /etc/gowebd/repomap
repomap-dryrun: go-build
./wit-test --no-gui --repomap /etc/gowebd/repomap --dry-run
test: go-build
./wit-test --no-gui --make-install --test

22
argv.go
View File

@ -6,7 +6,6 @@ package main
*/ */
import ( import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/debugger" "go.wit.com/lib/debugger"
"go.wit.com/lib/gui/logsettings" "go.wit.com/lib/gui/logsettings"
"go.wit.com/log" "go.wit.com/log"
@ -15,21 +14,26 @@ import (
var argv args var argv args
type args struct { type args struct {
TestBuild bool `arg:"--test-build" help:"try appropriate 'go build'"` TestBuild *EmptyCmd `arg:"subcommand:build" help:"try appropriate 'go build'"`
DebBuild bool `arg:"--debian" help:"build missing .deb packages"` DebBuild *EmptyCmd `arg:"subcommand:debian" help:"build missing .deb packages"`
MakeInstall *EmptyCmd `arg:"subcommand:install" help:"run make install in each repo"`
ListPkgs *EmptyCmd `arg:"subcommand:list" help:"list all the packages on mirrors.wit.com"`
Clone *EmptyCmd `arg:"subcommand:repomap-clone" help:"go-clone from a gowebd repomap"`
Upgrade *EmptyCmd `arg:"subcommand:upgrade" help:"apt upgrade packages installed from mirrors.wit.com"`
RepoMap string `arg:"--repomap" help:"location of the repomap"`
Release bool `arg:"--release" help:"use go-deb --release"` Release bool `arg:"--release" help:"use go-deb --release"`
DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
ListPkgs bool `arg:"--list" help:"list all the packages on mirrors.wit.com"` Verbose bool `arg:"--verbose" help:"be loud about it"`
Upgrade bool `arg:"--apt-upgrade" help:"apt install on every mirrors.wit.com package already installed"`
MakeInstall bool `arg:"--make-install" help:"run make install in each repo"`
RepoMap string `arg:"--repomap" help:"parse a repomap from gowebd"`
Recursive bool `arg:"--recursive" help:"go-clone --recursive"` Recursive bool `arg:"--recursive" help:"go-clone --recursive"`
Test bool `arg:"--test" help:"test build after everything else"` Test bool `arg:"--test" help:"test build after everything else"`
Bash bool `arg:"--bash" help:"generate bash completion"`
BashAuto []string `arg:"--auto-complete" help:"does the actual autocompletion"`
}
type EmptyCmd struct {
} }
func init() { func init() {
arg.MustParse(&argv)
if debugger.ArgDebug() { if debugger.ArgDebug() {
log.Info("cmd line --debugger == true") log.Info("cmd line --debugger == true")
go func() { go func() {

87
argvAutocomplete.go Normal file
View File

@ -0,0 +1,87 @@
package main
import (
"fmt"
"os"
"strings"
)
/*
handles shell autocomplete
*/
// used for shell auto completion
var ARGNAME string = "wit-test" // todo: get this from $0 ?
func (args) doBashAuto() {
argv.doBashHelp()
switch argv.BashAuto[0] {
case "list":
fmt.Println("--all --mine --favorites --private")
case "debian":
fmt.Println("--dry-run")
case "build":
fmt.Println("--verbose")
case "repomap-clone":
fmt.Println("--repomap")
default:
if strings.HasSuffix(argv.BashAuto[0], ARGNAME) {
// list the subcommands here
fmt.Println("--bash list build debian repomap-clone")
}
}
os.Exit(0)
}
// 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.argpp.WriteHelp(os.Stderr)
// return
}
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, "list: show every package on mirrors.wit.com")
fmt.Fprintln(os.Stderr, "build: go build every package that identifies as a binary")
fmt.Fprintln(os.Stderr, "install: go install every package into ~/go/bin")
fmt.Fprintln(os.Stderr, "repomap-clone: go-clone every package from a gowebd repomap")
fmt.Fprintln(os.Stderr, "")
}
// complete -F forge --bash forge
func (args) doBash() {
fmt.Println("# add this in your bashrc:")
fmt.Println("")
fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash")
fmt.Println("#")
fmt.Println("# todo: make this output work/parse with:")
fmt.Println("# complete -C " + ARGNAME + " --bash go")
fmt.Println("")
fmt.Println("_" + ARGNAME + "_complete()")
fmt.Println("{")
fmt.Println(" # sets local to this func vars")
fmt.Println(" local cur prev all")
fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}")
fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}")
fmt.Println(" all=${COMP_WORDS[@]}")
fmt.Println("")
fmt.Println(" # this is where we generate the go-arg output")
fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)")
fmt.Println("")
fmt.Println(" # this compares the command line input from the user")
fmt.Println(" # to whatever strings we output")
fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS")
fmt.Println(" return 0")
fmt.Println("}")
fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME)
fmt.Println("")
fmt.Println("# copy and paste the above into your bash shell should work")
os.Exit(0)
}

31
main.go
View File

@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"unicode" "unicode"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/log" "go.wit.com/log"
@ -25,6 +26,16 @@ var debnames map[*gitpb.Repo]string
func main() { func main() {
me = new(autoType) me = new(autoType)
me.argpp = arg.MustParse(&argv)
if argv.Bash {
argv.doBash()
os.Exit(0)
}
if len(argv.BashAuto) != 0 {
argv.doBashAuto()
os.Exit(0)
}
failed = make(map[*gitpb.Repo]string) failed = make(map[*gitpb.Repo]string)
state = make(map[*gitpb.Repo]string) state = make(map[*gitpb.Repo]string)
@ -36,12 +47,14 @@ func main() {
me.myGui = gui.New() me.myGui = gui.New()
me.myGui.Default() me.myGui.Default()
if argv.Clone != nil {
if argv.RepoMap != "" { if argv.RepoMap != "" {
repomap(argv.RepoMap) repomap(argv.RepoMap)
okExit("") okExit("")
} }
}
if argv.Upgrade { if argv.Upgrade != nil {
if argv.DryRun { if argv.DryRun {
log.Info("--dry-run", []string{"apt", "update"}) log.Info("--dry-run", []string{"apt", "update"})
} else { } else {
@ -68,7 +81,7 @@ func main() {
okExit("installed") okExit("installed")
} }
if argv.ListPkgs { if argv.ListPkgs != nil {
log.DaemonMode(true) log.DaemonMode(true)
defer log.DaemonMode(false) defer log.DaemonMode(false)
fmt.Println("Installed Packages:") fmt.Println("Installed Packages:")
@ -184,18 +197,26 @@ func main() {
if argv.DryRun { if argv.DryRun {
continue continue
} }
if argv.TestBuild { if argv.TestBuild != nil {
if argv.DryRun { if argv.DryRun {
continue continue
} }
if argv.Verbose {
verbose := []string{"-v", "-x"}
if err := me.forge.Build(check, verbose); err != nil {
log.Warn("BUILD FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
}
} else {
if err := me.forge.Build(check, nil); err != nil { if err := me.forge.Build(check, nil); err != nil {
log.Warn("BUILD FAILED", check.GetGoPath(), err) log.Warn("BUILD FAILED", check.GetGoPath(), err)
failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err) failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
} }
}
continue continue
} }
if argv.MakeInstall { if argv.MakeInstall != nil {
log.Info("STARTING 'make install' in", check.GetGoPath()) log.Info("STARTING 'make install' in", check.GetGoPath())
if argv.DryRun { if argv.DryRun {
continue continue
@ -207,7 +228,7 @@ func main() {
continue continue
} }
} }
if argv.DebBuild { if argv.DebBuild != nil {
buildDeb() buildDeb()
} }
if len(failed) != 0 { if len(failed) != 0 {

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
) )
@ -9,16 +10,7 @@ var me *autoType
// this app's variables // this app's variables
type autoType struct { type autoType struct {
// allrepos map[string]*repo argpp *arg.Parser // go-arg preprocessor
myGui *gui.Node myGui *gui.Node // the gui handle
forge *forgepb.Forge // your customized repo preferences and settings
// the window from the /lib/gui/gowit package
// lw *gadgets.BasicWindow
// our view of the repositories
// repos *repoWindow
// repoList *repolist.RepoList
// your customized repo preferences and settings
forge *forgepb.Forge
} }