new argv bash autocomplete

This commit is contained in:
Jeff Carr 2025-09-25 02:24:17 -05:00
parent 6732640068
commit 21313117b7
3 changed files with 41 additions and 42 deletions

46
argv.go
View File

@ -9,21 +9,21 @@ package main
*/ */
import ( import (
"fmt"
"os" "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/lib/gui/prep"
"go.wit.com/log" "go.wit.com/log"
) )
var argv args var argv args
type args struct { type args struct {
TestBuild *EmptyCmd `arg:"subcommand:build" help:"try appropriate 'go build'"` TestBuild *DefaultCmd `arg:"subcommand:build" help:"try appropriate 'go build'"`
DebBuild *EmptyCmd `arg:"subcommand:debian" help:"build missing .deb packages"` DebBuild *DebianCmd `arg:"subcommand:debian" help:"build missing .deb packages"`
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 *DefaultCmd `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"` 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"`
@ -38,6 +38,18 @@ type args struct {
Max int32 `arg:"--max" help:"stop building after max builds"` Max int32 `arg:"--max" help:"stop building after max builds"`
} }
type DebianCmd struct {
DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
Verbose bool `arg:"--verbose" help:"be loud about it"`
Force bool `arg:"--force" help:"rebuild everything"`
}
type DefaultCmd struct {
DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
Verbose bool `arg:"--verbose" help:"be loud about it"`
Force bool `arg:"--force" help:"rebuild everything"`
}
type EmptyCmd struct { type EmptyCmd struct {
} }
@ -68,25 +80,15 @@ func (args) Version() string {
handles shell autocomplete handles shell autocomplete
*/ */
func (a args) DoAutoComplete(argv []string) { func (args) Appname() string {
switch argv[0] { return ARGNAME
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")
} }
func (a args) DoAutoComplete(pb *prep.Auto) {
if pb.Cmd == "" {
pb.Autocomplete3([]string{"--bash", "build", "debian", "install", "macos"})
} else {
pb.SubCommand(pb.Argv...)
} }
os.Exit(0) os.Exit(0)
} }

View File

@ -10,7 +10,6 @@ import (
"path/filepath" "path/filepath"
"unicode" "unicode"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gui/prep" "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"
@ -31,9 +30,7 @@ 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.auto = prep.Bash3(&argv) // add support for bash autocomplete with go-arg
// me.myGui = prep.Gui() // prepares the GUI package for go-args
me.argpp = arg.MustParse(&argv)
dumpDebug() dumpDebug()

View File

@ -4,7 +4,7 @@
package main package main
import ( import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
) )
@ -13,7 +13,7 @@ var me *autoType
// this app's variables // this app's variables
type autoType struct { type autoType struct {
argpp *arg.Parser // go-arg preprocessor auto *prep.Auto // more experiments for bash handling
forge *forgepb.Forge // your customized repo preferences and settings forge *forgepb.Forge // your customized repo preferences and settings
machine *zoopb.Machine // your customized repo preferences and settings machine *zoopb.Machine // your customized repo preferences and settings
} }