cleanups due to autocomplete support
This commit is contained in:
parent
5802e0f214
commit
7e47940796
66
Makefile
66
Makefile
|
@ -2,82 +2,30 @@ VERSION = $(shell git describe --tags)
|
|||
GUIVERSION = $(shell git describe --tags)
|
||||
BUILDTIME = $(shell date +%Y.%m.%d)
|
||||
|
||||
all: go-build
|
||||
@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"
|
||||
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}"
|
||||
|
||||
vet:
|
||||
GO111MODULE=off go vet
|
||||
|
||||
only-me: go-build
|
||||
./wit-test --only-me
|
||||
|
||||
stderr: go-build
|
||||
echo "writing to /tmp/wit-test.log"
|
||||
./wit-test >/tmp/wit-test.log 2>&1
|
||||
|
||||
goimports:
|
||||
reset
|
||||
goimports -w *.go
|
||||
# // to globally reset paths:
|
||||
# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go
|
||||
|
||||
gocui: go-build
|
||||
./wit-test --gui gocui >/tmp/wit-test.log 2>&1
|
||||
|
||||
install: goimports
|
||||
GO111MODULE=off go install \
|
||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||
clean:
|
||||
rm -f go.*
|
||||
|
||||
check-git-clean:
|
||||
@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
22
argv.go
|
@ -6,7 +6,6 @@ package main
|
|||
*/
|
||||
|
||||
import (
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/debugger"
|
||||
"go.wit.com/lib/gui/logsettings"
|
||||
"go.wit.com/log"
|
||||
|
@ -15,21 +14,26 @@ import (
|
|||
var argv args
|
||||
|
||||
type args struct {
|
||||
TestBuild bool `arg:"--test-build" help:"try appropriate 'go build'"`
|
||||
DebBuild bool `arg:"--debian" help:"build missing .deb packages"`
|
||||
TestBuild *EmptyCmd `arg:"subcommand:build" help:"try appropriate 'go build'"`
|
||||
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"`
|
||||
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"`
|
||||
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"`
|
||||
Verbose bool `arg:"--verbose" help:"be loud about it"`
|
||||
Recursive bool `arg:"--recursive" help:"go-clone --recursive"`
|
||||
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() {
|
||||
arg.MustParse(&argv)
|
||||
|
||||
if debugger.ArgDebug() {
|
||||
log.Info("cmd line --debugger == true")
|
||||
go func() {
|
||||
|
|
|
@ -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
31
main.go
|
@ -7,6 +7,7 @@ import (
|
|||
"path/filepath"
|
||||
"unicode"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/log"
|
||||
|
||||
|
@ -25,6 +26,16 @@ var debnames map[*gitpb.Repo]string
|
|||
|
||||
func main() {
|
||||
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)
|
||||
state = make(map[*gitpb.Repo]string)
|
||||
|
@ -36,12 +47,14 @@ func main() {
|
|||
me.myGui = gui.New()
|
||||
me.myGui.Default()
|
||||
|
||||
if argv.Clone != nil {
|
||||
if argv.RepoMap != "" {
|
||||
repomap(argv.RepoMap)
|
||||
okExit("")
|
||||
}
|
||||
}
|
||||
|
||||
if argv.Upgrade {
|
||||
if argv.Upgrade != nil {
|
||||
if argv.DryRun {
|
||||
log.Info("--dry-run", []string{"apt", "update"})
|
||||
} else {
|
||||
|
@ -68,7 +81,7 @@ func main() {
|
|||
okExit("installed")
|
||||
}
|
||||
|
||||
if argv.ListPkgs {
|
||||
if argv.ListPkgs != nil {
|
||||
log.DaemonMode(true)
|
||||
defer log.DaemonMode(false)
|
||||
fmt.Println("Installed Packages:")
|
||||
|
@ -184,18 +197,26 @@ func main() {
|
|||
if argv.DryRun {
|
||||
continue
|
||||
}
|
||||
if argv.TestBuild {
|
||||
if argv.TestBuild != nil {
|
||||
if argv.DryRun {
|
||||
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 {
|
||||
log.Warn("BUILD FAILED", check.GetGoPath(), err)
|
||||
failed[check] = fmt.Sprintf("%s %s %v", "go build", check.GetGoPath(), err)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if argv.MakeInstall {
|
||||
if argv.MakeInstall != nil {
|
||||
log.Info("STARTING 'make install' in", check.GetGoPath())
|
||||
if argv.DryRun {
|
||||
continue
|
||||
|
@ -207,7 +228,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
}
|
||||
if argv.DebBuild {
|
||||
if argv.DebBuild != nil {
|
||||
buildDeb()
|
||||
}
|
||||
if len(failed) != 0 {
|
||||
|
|
16
structs.go
16
structs.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
)
|
||||
|
@ -9,16 +10,7 @@ var me *autoType
|
|||
|
||||
// this app's variables
|
||||
type autoType struct {
|
||||
// allrepos map[string]*repo
|
||||
myGui *gui.Node
|
||||
|
||||
// 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
|
||||
argpp *arg.Parser // go-arg preprocessor
|
||||
myGui *gui.Node // the gui handle
|
||||
forge *forgepb.Forge // your customized repo preferences and settings
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue