more argv improvements

This commit is contained in:
Jeff Carr 2024-12-27 04:36:29 -06:00
parent 9818e8d1ee
commit 8b3be0ab42
7 changed files with 59 additions and 80 deletions

View File

@ -35,19 +35,19 @@ gocui: install
forge --gui gocui >/tmp/forge.log 2>&1 forge --gui gocui >/tmp/forge.log 2>&1
private: install private: install
forge find --private forge list --private
fix: install fix: install
forge --fix find --all forge --fix list --all
list-all: install list-all: install
forge list --all forge list --all
git-reset: install git-reset: install
forge --do-git-reset find --all forge --do-git-reset list --all
readonly: install readonly: install
forge --list find --readonly forge --list list --readonly
config: install config: install
forge --config forge --config
@ -74,7 +74,7 @@ patches-list: install
forge --list-patchset forge --list-patchset
dirty: install dirty: install
forge --no-gui find --all --dirty forge dirty --all
restart: restart:
reset reset

12
argv.go
View File

@ -7,32 +7,30 @@ package main
var argv args var argv args
type FindCmd struct { type FindCmd struct {
All bool `arg:"--all" help:"select every repo"` All bool `arg:"--all" help:"select every repo (the default)"`
ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
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"`
Private bool `arg:"--private" help:"private repos from your .config/forge/"` Private bool `arg:"--private" help:"your private repos from your .config/forge/"`
// ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
} }
type args struct { type args struct {
Find *FindCmd `arg:"subcommand:find" help:"select repos (for example, --all or --mine)"`
List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"` List *FindCmd `arg:"subcommand:list" help:"just show a table of the current state"`
Dirty *FindCmd `arg:"subcommand:dirty" help:"check if your git repos are dirty"`
User *FindCmd `arg:"subcommand:user" help:"git checkout user"` User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"` Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
Master *FindCmd `arg:"subcommand:master" help:"git checkout master"` Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"` GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Config bool `arg:"--config" help:"show your .config/forge/ settings"` Config *FindCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"` ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"`
DryRun bool `arg:"--dry-run" help:"show what would be run"` DryRun bool `arg:"--dry-run" help:"show what would be run"`
Fix bool `arg:"--fix" help:"fix config, save config & exit"` Fix bool `arg:"--fix" help:"fix config, save config & exit"`
Delete string `arg:"--delete" help:"delete this repo"` Delete string `arg:"--delete" help:"delete this repo"`
URL string `arg:"--connect" help:"gowebd url"` URL string `arg:"--connect" help:"gowebd url"`
Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"`
// List bool `arg:"--list" help:"just show a table of the current state"`
GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"` GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"`
Scan bool `arg:"--scan" help:"reload protobuf from .git/"` Scan bool `arg:"--scan" help:"reload protobuf from .git/"`
Force bool `arg:"--force" help:"force redo things"` Force bool `arg:"--force" help:"force redo things"`
Dirty bool `arg:"--dirty" help:"update git CheckDirty()"`
PatchSet string `arg:"--patchset" help:"make patch set"` PatchSet string `arg:"--patchset" help:"make patch set"`
} }

View File

@ -34,7 +34,7 @@ func doCobol() {
log.DaemonMode(true) log.DaemonMode(true)
// log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type")) // log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type"))
log.Info(standardStart8("gopath", "cur name", "age", "target", "master", "devel", "user", "curver", "repo type")) log.Info(standardStart8("repopath", "cur name", "age", "target", "master", "devel", "user", "curver", "repo type"))
all := me.found.SortByFullPath() all := me.found.SortByFullPath()
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()
@ -133,7 +133,8 @@ func verifyPrint(repo *gitpb.Repo) {
if repo.IsDirty() { if repo.IsDirty() {
end += "(dirty) " end += "(dirty) "
} }
s := make(map[string]string) // s := make(map[string]string)
/*
if !verify(repo, s) { if !verify(repo, s) {
log.Info("going to delete", repo.GetGoPath()) log.Info("going to delete", repo.GetGoPath())
if argv.Fix { if argv.Fix {
@ -143,18 +144,21 @@ func verifyPrint(repo *gitpb.Repo) {
log.Info("need argv --fix to delete", repo.GetGoPath()) log.Info("need argv --fix to delete", repo.GetGoPath())
} }
} }
*/
var mhort string = s["mver"] // master version var mhort string = repo.GetMasterVersion()
var dhort string = s["dver"] // devel version var dhort string = repo.GetDevelVersion()
var uhort string = s["uver"] // user version var uhort string = repo.GetUserVersion()
var thort string = s["tver"] // target version var thort string = repo.GetTargetVersion()
var chort string = s["cver"] // current version var chort string = repo.GetCurrentBranchVersion()
var cname string = s["cname"] // current branch name git is on now var cname string = repo.GetCurrentBranchName()
var gopath string = repo.GetGoPath()
var rtype string = repo.GetRepoType()
age := shell.FormatDuration(repo.NewestAge()) age := shell.FormatDuration(repo.NewestAge())
// start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], cname, mhort, uhort, s["rtype"]) start := standardStart8(gopath, cname, age, thort, mhort, dhort, uhort, chort, rtype)
start := standardStart8(s["gopath"], cname, age, thort, mhort, dhort, uhort, chort, s["rtype"])
if me.forge.Config.IsReadOnly(repo.GetGoPath()) { if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
end += "(readonly) " end += "(readonly) "

View File

@ -39,7 +39,7 @@ func doGitPull() {
func doCheckDirty() { func doCheckDirty() {
now := time.Now() now := time.Now()
all := me.forge.Repos.SortByFullPath() all := me.found.SortByFullPath()
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()
dirty := repo.IsDirty() dirty := repo.IsDirty()

View File

@ -3,23 +3,20 @@ package main
import "go.wit.com/log" import "go.wit.com/log"
// retuns true if nothing was done // retuns true if nothing was done
func findConfig() bool { func findConfig(fargv *FindCmd) {
var done bool = false if fargv == nil {
if argv.Find != nil { findConfigAll()
if argv.Find.Mine { return
}
if fargv.Mine {
findConfigMine() findConfigMine()
done = true return
} }
if argv.Find.All { if fargv.All {
findConfigAll() findConfigAll()
done = true return
} }
}
if !done {
findConfigAll() findConfigAll()
done = true
}
return done
} }
// finds config repos that are writable // finds config repos that are writable

View File

@ -1,9 +1,6 @@
package main package main
import ( // by default, work against every repo
"go.wit.com/log"
)
func (f *FindCmd) findRepos() { func (f *FindCmd) findRepos() {
if f == nil { if f == nil {
findMine() findMine()
@ -29,7 +26,7 @@ func (f *FindCmd) findRepos() {
return return
} }
findMine() findAll(f)
} }
func findRepos(fargv *FindCmd) { func findRepos(fargv *FindCmd) {
@ -93,26 +90,10 @@ func findFavorites() {
} }
} }
// func (f *FindCmd) findRepos() {
func findAll(fargv *FindCmd) { func findAll(fargv *FindCmd) {
all := me.forge.Repos.SortByFullPath() all := me.forge.Repos.SortByFullPath()
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()
me.found.AppendUniqueGoPath(repo) me.found.AppendUniqueGoPath(repo)
if me.forge.Config.IsReadOnly(repo.GetGoPath()) && !fargv.ReadOnly {
if repo.ReadOnly {
continue
} }
log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GetGoPath())
repo.ReadOnly = true
configSave = true
continue
}
}
/*
if configsave {
log.Info("should ConfigSave here")
me.forge.Repos.ConfigSave()
}
*/
} }

13
main.go
View File

@ -87,26 +87,25 @@ func main() {
} }
// first find the repos or gopaths to operate on // first find the repos or gopaths to operate on
if argv.Config { if argv.Config != nil {
if findConfig() { findConfig(argv.Config)
me.forge.ConfigPrintTable() me.forge.ConfigPrintTable()
okExit("") okExit("")
} }
}
log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge") log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge")
// now, do something to all of them (or just print out a table of them) // now, do something to all of them (or just print out a table of them)
var done bool = false var done bool = false
if argv.Dirty { if argv.Dirty != nil {
findRepos(argv.Find) argv.Dirty.findRepos()
doCheckDirty() doCheckDirty()
okExit("") okExit("")
done = true done = true
} }
if argv.Scan { if argv.Scan {
findRepos(argv.Find) findRepos(argv.List)
doScan() doScan()
done = true done = true
} }
@ -118,7 +117,7 @@ func main() {
} }
if argv.GitReset { if argv.GitReset {
findRepos(argv.Find) findRepos(argv.List)
doGitReset() doGitReset()
done = true done = true
} }