make args work again
This commit is contained in:
parent
49820069c9
commit
e629211edd
35
argv.go
35
argv.go
|
@ -9,6 +9,9 @@ package main
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"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"
|
||||||
|
@ -22,6 +25,7 @@ type args struct {
|
||||||
MacBuild *EmptyCmd `arg:"subcommand:macos" help:"build macos packages"`
|
MacBuild *EmptyCmd `arg:"subcommand:macos" help:"build macos packages"`
|
||||||
MakeInstall *EmptyCmd `arg:"subcommand:install" help:"run make install in each repo"`
|
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"`
|
ListPkgs *EmptyCmd `arg:"subcommand:list" help:"list all the packages on mirrors.wit.com"`
|
||||||
|
Test *EmptyCmd `arg:"subcommand:test" help:"test build everything first"`
|
||||||
Clone *EmptyCmd `arg:"subcommand:repomap-clone" help:"go-clone from a gowebd repomap"`
|
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"`
|
Upgrade *EmptyCmd `arg:"subcommand:upgrade" help:"apt upgrade packages installed from mirrors.wit.com"`
|
||||||
RepoMap string `arg:"--repomap" help:"location of the repomap"`
|
RepoMap string `arg:"--repomap" help:"location of the repomap"`
|
||||||
|
@ -30,10 +34,8 @@ type args struct {
|
||||||
Verbose bool `arg:"--verbose" help:"be loud about it"`
|
Verbose bool `arg:"--verbose" help:"be loud about it"`
|
||||||
Force bool `arg:"--force" help:"rebuild everything"`
|
Force bool `arg:"--force" help:"rebuild everything"`
|
||||||
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"`
|
|
||||||
WITCOM bool `arg:"--witcom" help:"add the GPL header"`
|
WITCOM bool `arg:"--witcom" help:"add the GPL header"`
|
||||||
Bash bool `arg:"--bash" help:"generate bash completion"`
|
Max int32 `arg:"--max" help:"stop building after max builds"`
|
||||||
BashAuto []string `arg:"--auto-complete" help:"does the actual autocompletion"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmptyCmd struct {
|
type EmptyCmd struct {
|
||||||
|
@ -61,3 +63,30 @@ func init() {
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
return "wit-test " + VERSION + " Built on " + BUILDTIME
|
return "wit-test " + VERSION + " Built on " + BUILDTIME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
handles shell autocomplete
|
||||||
|
*/
|
||||||
|
|
||||||
|
func (a args) DoAutoComplete(argv []string) {
|
||||||
|
switch argv[0] {
|
||||||
|
case "list":
|
||||||
|
fmt.Println("--all --mine --favorites --private")
|
||||||
|
case "debian":
|
||||||
|
fmt.Println("--dry-run --force --release --verbose macos --max")
|
||||||
|
case "upgrade":
|
||||||
|
fmt.Println("--dry-run")
|
||||||
|
case "build":
|
||||||
|
fmt.Println("--verbose --force")
|
||||||
|
case "install":
|
||||||
|
fmt.Println("--verbose")
|
||||||
|
case "repomap-clone":
|
||||||
|
fmt.Println("--repomap")
|
||||||
|
default:
|
||||||
|
if argv[0] == ARGNAME {
|
||||||
|
// list the subcommands here
|
||||||
|
fmt.Println("--bash list build debian install repomap-clone upgrade")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
|
@ -1,94 +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 (
|
|
||||||
"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 "upgrade":
|
|
||||||
fmt.Println("--dry-run")
|
|
||||||
case "build":
|
|
||||||
fmt.Println("--verbose")
|
|
||||||
case "install":
|
|
||||||
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 install repomap-clone upgrade")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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)
|
|
||||||
}
|
|
16
doDebian.go
16
doDebian.go
|
@ -15,11 +15,15 @@ func buildDeb() {
|
||||||
log.DaemonMode(true)
|
log.DaemonMode(true)
|
||||||
defer log.DaemonMode(false)
|
defer log.DaemonMode(false)
|
||||||
|
|
||||||
if err := doInstall(); err != nil {
|
if argv.Test != nil {
|
||||||
log.Info("doInstall() failed", err)
|
if err := doInstall(); err != nil {
|
||||||
badExit(err)
|
log.Info("doInstall() failed", err)
|
||||||
|
badExit(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var counter int
|
||||||
|
|
||||||
all := me.forge.Repos.SortByFullPath()
|
all := me.forge.Repos.SortByFullPath()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
var cmd []string
|
var cmd []string
|
||||||
|
@ -67,6 +71,12 @@ func buildDeb() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
counter += 1
|
||||||
|
|
||||||
|
if counter > int(argv.Max) {
|
||||||
|
okExit("did --max builds")
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
build-darwin:
|
build-darwin:
|
||||||
GOOS=darwin GOARCH=amd64 GO111MODULE=off go build -v -o go-clone-darwin.x86 \
|
GOOS=darwin GOARCH=amd64 GO111MODULE=off go build -v -o go-clone-darwin.x86 \
|
||||||
|
|
30
main.go
30
main.go
|
@ -11,7 +11,7 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/prep"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
|
@ -22,22 +22,19 @@ import (
|
||||||
var VERSION string
|
var VERSION string
|
||||||
var BUILDTIME string
|
var BUILDTIME string
|
||||||
|
|
||||||
|
// used for shell auto completion
|
||||||
|
var ARGNAME string = "wit-test" // todo: get this from $0 ?
|
||||||
|
|
||||||
var failed map[*gitpb.Repo]string
|
var failed map[*gitpb.Repo]string
|
||||||
var state map[*gitpb.Repo]string
|
var state map[*gitpb.Repo]string
|
||||||
var debnames map[*gitpb.Repo]string
|
var debnames map[*gitpb.Repo]string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
me = new(autoType)
|
me = new(autoType)
|
||||||
|
prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be: prep.Bash(argv)
|
||||||
|
// me.myGui = prep.Gui() // prepares the GUI package for go-args
|
||||||
me.argpp = arg.MustParse(&argv)
|
me.argpp = arg.MustParse(&argv)
|
||||||
|
|
||||||
if argv.Bash {
|
|
||||||
argv.doBash()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
if len(argv.BashAuto) != 0 {
|
|
||||||
argv.doBashAuto()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
dumpDebug()
|
dumpDebug()
|
||||||
|
|
||||||
failed = make(map[*gitpb.Repo]string)
|
failed = make(map[*gitpb.Repo]string)
|
||||||
|
@ -120,21 +117,6 @@ func main() {
|
||||||
okExit("EVERYTHING BUILT!")
|
okExit("EVERYTHING BUILT!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Test {
|
|
||||||
homeDir, _ := os.UserHomeDir()
|
|
||||||
|
|
||||||
testdir := filepath.Join(homeDir, "go/src/go.wit.com/apps/utils/wit-utils/go-clone-test/")
|
|
||||||
os.Chdir(testdir)
|
|
||||||
shell.RunRealtime([]string{"go", "install"})
|
|
||||||
|
|
||||||
workdir := filepath.Join(homeDir, "gowork")
|
|
||||||
if err := os.MkdirAll(workdir, os.ModePerm); err != nil {
|
|
||||||
badExit(err)
|
|
||||||
}
|
|
||||||
os.Chdir(workdir)
|
|
||||||
shell.RunRealtime([]string{"go-clone-test"})
|
|
||||||
}
|
|
||||||
|
|
||||||
okExit("everything compiled")
|
okExit("everything compiled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue