more accurate autocomplete

This commit is contained in:
Jeff Carr 2025-09-25 00:44:16 -05:00
parent 71a5b271a8
commit a478df2dcc
5 changed files with 93 additions and 96 deletions

View File

@ -9,7 +9,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
default: install-verbose tag default: install-verbose tag
tag: tag:
forge tag list forge show tag
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet

91
argv.go
View File

@ -34,12 +34,15 @@ type args struct {
type ShowCmd struct { type ShowCmd struct {
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"show dirty git repos"` Dirty *EmptyCmd `arg:"subcommand:dirty" help:"show dirty git repos"`
List *EmptyCmd `arg:"subcommand:list" help:"print a table of the current repos"` Repo *RepoCmd `arg:"subcommand:repo" help:"print a table of the current repos"`
Tag *TagCmd `arg:"subcommand:tag" help:"manage git tags"` Tag *TagCmd `arg:"subcommand:tag" help:"show git tags"`
Build string `arg:"--build" help:"build a repo"` // Build string `arg:"--build" help:"build a repo"`
Install string `arg:"--install" help:"install a repo"` // Install string `arg:"--install" help:"install a repo"`
BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"` // BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"`
URL string `arg:"--connect" help:"forge url"` // URL string `arg:"--connect" help:"forge url"`
}
type RepoCmd struct {
All bool `arg:"--all" help:"select every repo (the default)"` All bool `arg:"--all" help:"select every repo (the default)"`
Mine bool `arg:"--mine" help:"your repos as defined in the forge config"` Mine bool `arg:"--mine" help:"your repos as defined in the forge config"`
Favorites bool `arg:"--favorites" help:"your repos configured as favorites"` Favorites bool `arg:"--favorites" help:"your repos configured as favorites"`
@ -65,8 +68,8 @@ type CommitCmd struct {
type testCmd string type testCmd string
type CleanCmd struct { type CleanCmd struct {
Verify *EmptyCmd `arg:"subcommand:verify" help:"rescan repo"` // Verify *EmptyCmd `arg:"subcommand:verify" help:"rescan repo"`
Repo string `arg:"--repo" help:"which repo to look at"` // Repo string `arg:"--repo" help:"which repo to look at"`
} }
type CleanDevelCmd struct { type CleanDevelCmd struct {
@ -87,9 +90,10 @@ type SubmitCmd struct {
} }
type PullCmd struct { type PullCmd struct {
Check *EmptyCmd `arg:"subcommand:check" help:"check repo versions"` Force bool `arg:"--force" help:"try to strong-arm things"`
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"only check dirty repos"` // Check *EmptyCmd `arg:"subcommand:check" help:"check repo versions"`
Patches *EmptyCmd `arg:"subcommand:patches" help:"only check repos with patches"` // Dirty *EmptyCmd `arg:"subcommand:dirty" help:"only check dirty repos"`
// Patches *EmptyCmd `arg:"subcommand:patches" help:"only check repos with patches"`
} }
type TagCmd struct { type TagCmd struct {
@ -98,6 +102,27 @@ type TagCmd struct {
Delete string `arg:"--delete" help:"delete a tag"` Delete string `arg:"--delete" help:"delete a tag"`
} }
type CheckoutCmd struct {
User *EmptyCmd `arg:"subcommand:user" help:"git checkout user"`
Devel *EmptyCmd `arg:"subcommand:devel" help:"git checkout devel"`
Master *EmptyCmd `arg:"subcommand:master" help:"git checkout master"`
}
type MergeCmd struct {
All bool `arg:"--all" help:"merge all"`
Devel *EmptyCmd `arg:"subcommand:devel" help:"merge user to devel"`
Master *EmptyCmd `arg:"subcommand:master" help:"merge devel to master"`
Publish *EmptyCmd `arg:"subcommand:publish" help:"increment versions and publish master branch"`
}
type ConfigCmd struct {
Add *ConfigAddCmd `arg:"subcommand:add" help:"add a config setting"`
Fix *EmptyCmd `arg:"subcommand:fix" help:"fix .config/forge/ and/or repos.pb protobuf file"`
List *EmptyCmd `arg:"subcommand:list" help:"list your config settings"`
Delete string `arg:"--delete" help:"delete this repo"`
Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"`
}
type ConfigAddCmd struct { type ConfigAddCmd struct {
Path string `arg:"--path" help:"absolute path of the git repo"` Path string `arg:"--path" help:"absolute path of the git repo"`
GoPath string `arg:"--gopath" help:"GO path of the git repo"` GoPath string `arg:"--gopath" help:"GO path of the git repo"`
@ -113,26 +138,6 @@ type ConfigAddCmd struct {
User string `arg:"--user" help:"the git user branch name"` User string `arg:"--user" help:"the git user branch name"`
} }
type CheckoutCmd struct {
User *EmptyCmd `arg:"subcommand:user" help:"git checkout user"`
Devel *EmptyCmd `arg:"subcommand:devel" help:"git checkout devel"`
Master *EmptyCmd `arg:"subcommand:master" help:"git checkout master"`
}
type MergeCmd struct {
Devel *EmptyCmd `arg:"subcommand:devel" help:"merge user to devel"`
Master *EmptyCmd `arg:"subcommand:master" help:"merge devel to master"`
Publish *EmptyCmd `arg:"subcommand:publish" help:"increment versions and publish master branch"`
}
type ConfigCmd struct {
Add *ConfigAddCmd `arg:"subcommand:add" help:"add a config setting"`
Fix *EmptyCmd `arg:"subcommand:fix" help:"fix .config/forge/ and/or repos.pb protobuf file"`
List *EmptyCmd `arg:"subcommand:list" help:"list your config settings"`
Delete string `arg:"--delete" help:"delete this repo"`
Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"`
}
func (args) Version() string { func (args) Version() string {
return ARGNAME + " " + VERSION + " Built on " + BUILDTIME return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
} }
@ -163,21 +168,6 @@ forge -- a tool to manage lots of git repos. forge includes a GUI and TUI.
` `
} }
// handles shell autocomplete
func DoAutoComplete(pb *prep.Auto) {
switch pb.Cmd {
case "show":
pb.SubCommand(pb.Cmd)
default:
if pb.Cmd == "" {
pb.Autocomplete2("checkout clean commit normal merge show")
} else {
pb.SubCommand(pb.Cmd)
}
}
os.Exit(0)
}
func (args) Appname() string { func (args) Appname() string {
return ARGNAME return ARGNAME
} }
@ -190,6 +180,11 @@ func ifBlank(arg string) bool {
return false return false
} }
func (a args) DoAutoComplete(autoArgv *prep.Auto) { func (a args) DoAutoComplete(pb *prep.Auto) {
DoAutoComplete(autoArgv) if pb.Cmd == "" {
pb.Autocomplete3([]string{"checkout", "clean", "commit", "config", "gui", "merge", "normal", "patch", "pull", "show"})
} else {
pb.SubCommand(pb.Argv...)
}
os.Exit(0)
} }

View File

@ -6,9 +6,7 @@ package main
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"time"
"go.wit.com/lib/gui/shell"
"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/log" "go.wit.com/log"
@ -58,6 +56,7 @@ if repo.IsSubset("user", "devel") {
func doClean() error { func doClean() error {
setForgeMode(forgepb.ForgeMode_CLEAN) setForgeMode(forgepb.ForgeMode_CLEAN)
/*
if argv.Clean.Verify != nil { if argv.Clean.Verify != nil {
stats := me.forge.RillRepos(checkRemoteBranches) stats := me.forge.RillRepos(checkRemoteBranches)
for path, stat := range stats { for path, stat := range stats {
@ -73,6 +72,7 @@ func doClean() error {
// log.Infof("%-30v %s %v\n", dur, path, stat.Err) // log.Infof("%-30v %s %v\n", dur, path, stat.Err)
return nil return nil
} }
*/
// fix this to work, then delete all the other options for "forge clean' // fix this to work, then delete all the other options for "forge clean'
if err := me.forge.DoAllCheckoutMaster(); err != nil { if err := me.forge.DoAllCheckoutMaster(); err != nil {

View File

@ -19,7 +19,7 @@ func doFind() *gitpb.Repos {
return findAll() return findAll()
} }
if argv.Show.Mine { if argv.Show.Repo.Mine {
return findMine() return findMine()
} }
@ -35,19 +35,19 @@ func findRepos() *gitpb.Repos {
return findMine() return findMine()
} }
if argv.Show.All { if argv.Show.Repo.All {
return findAll() return findAll()
} }
if argv.Show.Private { if argv.Show.Repo.Private {
return findPrivate() return findPrivate()
} }
if argv.Show.Mine { if argv.Show.Repo.Mine {
return findMine() return findMine()
} }
if argv.Show.Favorites { if argv.Show.Repo.Favorites {
return findFavorites() return findFavorites()
} }
@ -55,7 +55,7 @@ func findRepos() *gitpb.Repos {
return me.forge.FindDirty() return me.forge.FindDirty()
} }
if argv.Show.User { if argv.Show.Repo.User {
return findUser() return findUser()
} }

View File

@ -14,6 +14,7 @@ import (
// is every repo on the devel branch? // is every repo on the devel branch?
func doPull() error { func doPull() error {
/*
if argv.Pull.Check != nil { if argv.Pull.Check != nil {
// stats := me.forge.RillFuncError(rillPull) // stats := me.forge.RillFuncError(rillPull)
log.Info("TODO: actually git pull here? this is a bad idea. stopping.") log.Info("TODO: actually git pull here? this is a bad idea. stopping.")
@ -34,6 +35,7 @@ func doPull() error {
log.Infof("pull check %s pb.Len()=%d client.Len()=%d server.Len()=%d err=%v\n", regPB.URL, updatepb.Len(), regPB.ClientDataLen, regPB.ServerDataLen, err) log.Infof("pull check %s pb.Len()=%d client.Len()=%d server.Len()=%d err=%v\n", regPB.URL, updatepb.Len(), regPB.ClientDataLen, regPB.ServerDataLen, err)
return nil return nil
} }
*/
// below this, you must not be in 'normal' mode // below this, you must not be in 'normal' mode
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL { if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
@ -41,7 +43,7 @@ func doPull() error {
return nil return nil
} }
if argv.Force == true { if argv.Pull.Force {
now := time.Now() now := time.Now()
stats := me.forge.RillFuncError(rillPull) stats := me.forge.RillFuncError(rillPull)
count := me.forge.RillReload() count := me.forge.RillReload()