redoing argv handling

This commit is contained in:
Jeff Carr 2025-09-24 22:17:27 -05:00
parent e0520ca96d
commit 71a5b271a8
10 changed files with 143 additions and 159 deletions

144
argv.go
View File

@ -4,10 +4,10 @@
package main package main
import ( import (
"fmt"
"os" "os"
"go.wit.com/lib/gui/prep" "go.wit.com/lib/gui/prep"
"go.wit.com/log"
) )
/* /*
@ -17,27 +17,36 @@ import (
var argv args var argv args
type args struct { type args struct {
Help *EmptyCmd `arg:"subcommand:help" help:"New to forge? This is for you.'"` Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch branches using 'git checkout'"`
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch branches using 'git checkout'"` Clean *CleanCmd `arg:"subcommand:clean" help:"start over at the beginning"`
Clean *CleanCmd `arg:"subcommand:clean" help:"start over at the beginning"` Commit *CommitCmd `arg:"subcommand:commit" help:"'git commit' but errors out if on wrong branch"`
Commit *CommitCmd `arg:"subcommand:commit" help:"'git commit' but errors out if on wrong branch"` Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"`
Dirty *DirtyCmd `arg:"subcommand:dirty" help:"show dirty git repos"` Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"`
GitFetch *FindCmd `arg:"subcommand:fetch" help:"run 'git fetch master'"` Normal *NormalCmd `arg:"subcommand:normal" help:"set every repo to the default state for software development"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"` Patch *PatchCmd `arg:"subcommand:patch" help:"make patchsets"`
List *FindCmd `arg:"subcommand:list" help:"print a table of the current repos"` Pull *PullCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"` Show *ShowCmd `arg:"subcommand:show" help:"print out things"`
Normal *NormalCmd `arg:"subcommand:normal" help:"set every repo to the default state for software development"` All bool `arg:"--all" help:"git commit --all"`
Patch *PatchCmd `arg:"subcommand:patch" help:"make patchsets"` Force bool `arg:"--force" help:"try to strong-arm things"`
Pull *PullCmd `arg:"subcommand:pull" help:"run 'git pull'"` Verbose bool `arg:"--verbose" help:"show more output"`
Tag *TagCmd `arg:"subcommand:tag" help:"manage git tags"` }
URL string `arg:"--connect" help:"forge url"`
All bool `arg:"--all" help:"git commit --all"` type ShowCmd struct {
Build string `arg:"--build" help:"build a repo"` Dirty *EmptyCmd `arg:"subcommand:dirty" help:"show dirty git repos"`
Install string `arg:"--install" help:"install a repo"` List *EmptyCmd `arg:"subcommand:list" help:"print a table of the current repos"`
BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"` Tag *TagCmd `arg:"subcommand:tag" help:"manage git tags"`
Force bool `arg:"--force" help:"try to strong arm things"` Build string `arg:"--build" help:"build a repo"`
Verbose bool `arg:"--verbose" help:"show more output"` Install string `arg:"--install" help:"install a repo"`
BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"`
URL string `arg:"--connect" help:"forge url"`
All bool `arg:"--all" help:"select every repo (the default)"`
Mine bool `arg:"--mine" help:"your repos as defined in the forge config"`
Favorites bool `arg:"--favorites" help:"your repos configured as favorites"`
Private bool `arg:"--private" help:"your private repos from your .config/forge/"`
User bool `arg:"--user" help:"show repos on the user branch"`
Full bool `arg:"--full" help:"show full repo names"`
// ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
} }
type EmptyCmd struct { type EmptyCmd struct {
@ -49,7 +58,8 @@ type NormalCmd struct {
} }
type CommitCmd struct { type CommitCmd struct {
Submit bool `arg:"--submit" default:"true" help:"submit the patches to forge"` // Submit bool `arg:"--submit" default:"true" help:"submit the patches to forge"`
All bool `arg:"--all" default:"true" help:"git commit in all dirty repos"`
} }
type testCmd string type testCmd string
@ -103,6 +113,18 @@ 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 { type ConfigCmd struct {
Add *ConfigAddCmd `arg:"subcommand:add" help:"add a config setting"` 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"` Fix *EmptyCmd `arg:"subcommand:fix" help:"fix .config/forge/ and/or repos.pb protobuf file"`
@ -111,37 +133,29 @@ type ConfigCmd struct {
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)"`
} }
type CheckoutCmd struct {
User *FindCmd `arg:"subcommand:user" help:"git checkout user"`
Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"`
Master *FindCmd `arg:"subcommand:master" help:"git checkout master"`
}
type MergeCmd struct {
Devel *FindCmd `arg:"subcommand:devel" help:"merge user to devel"`
Master *FindCmd `arg:"subcommand:master" help:"merge devel to master"`
Publish *EmptyCmd `arg:"subcommand:publish" help:"increment versions and publish master branch"`
}
type DirtyCmd struct {
}
type FindCmd struct {
All bool `arg:"--all" help:"select every repo (the default)"`
Mine bool `arg:"--mine" help:"your repos as defined in the forge config"`
Favorites bool `arg:"--favorites" help:"your repos configured as favorites"`
Private bool `arg:"--private" help:"your private repos from your .config/forge/"`
Dirty bool `arg:"--dirty" help:"only use dirty git repos"`
User bool `arg:"--user" help:"show repos on the user branch"`
Full bool `arg:"--full" help:"show full repo names"`
// ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
}
func (args) Version() string { func (args) Version() string {
return ARGNAME + " " + VERSION + " Built on " + BUILDTIME return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
} }
// keep this small
func doHelp() {
log.Info("")
log.Info("forge -h : to see the available options")
log.Info("forge --bash : will create a bash autocomplete file")
log.Info("forge : with no arguements, forge tries to load a GO GUI plugin")
log.Info(" : there are two GUI plugins. terminal & GTK")
log.Info("")
log.Info("forge list : shows a table of all your repos")
log.Info("forge checkout : checks out all your repos to the same branch")
log.Info(" : the default is your user branch")
log.Info("forge clean : reverts all repos to the master branch")
log.Info("forge dirty : show all repos git reports as dirty")
log.Info("")
}
func (a args) Description() string { func (a args) Description() string {
// doHelp()
return ` return `
forge -- a tool to manage lots of git repos. forge includes a GUI and TUI. forge -- a tool to manage lots of git repos. forge includes a GUI and TUI.
@ -152,37 +166,13 @@ forge -- a tool to manage lots of git repos. forge includes a GUI and TUI.
// handles shell autocomplete // handles shell autocomplete
func DoAutoComplete(pb *prep.Auto) { func DoAutoComplete(pb *prep.Auto) {
switch pb.Cmd { switch pb.Cmd {
case "checkout": case "show":
pb.Autocomplete2("devel master user") pb.SubCommand(pb.Cmd)
case "clean":
pb.Autocomplete2("")
case "commit":
pb.Autocomplete2("--all")
case "config":
fmt.Println("add fix list")
case "dirty":
fmt.Println("")
case "gui":
fmt.Println("")
case "--gui":
pb.Autocomplete2("andlabs gocui")
case "list":
pb.Autocomplete2("--mine --favorites --dirty")
case "merge":
pb.Autocomplete2("devel master --all")
case "normal":
pb.Autocomplete2("on off")
case "pull":
pb.Autocomplete2("--force check")
case "patch":
fmt.Println("check get list repos submit show")
case "tag":
fmt.Println("list --delete clean")
default: default:
if pb.Cmd == "" { if pb.Cmd == "" {
pb.Autocomplete2("help list checkout clean commit dirty fetch gui normal merge patch pull tag --gui") pb.Autocomplete2("checkout clean commit normal merge show")
} else { } else {
pb.Autocomplete2("list checkout clean commit dirty normal merge tag") pb.SubCommand(pb.Cmd)
} }
} }
os.Exit(0) os.Exit(0)

View File

@ -3,12 +3,7 @@
package main package main
import ( /*
"fmt"
"go.wit.com/log"
)
func doBuild() error { func doBuild() error {
v := []string{} v := []string{}
if argv.Verbose { if argv.Verbose {
@ -45,3 +40,4 @@ func doInstall() error {
} }
return nil return nil
} }
*/

View File

@ -29,6 +29,30 @@ func checkRemoteBranches(repo *gitpb.Repo) error {
return nil return nil
} }
/*
if repo.DevelSubsetOfUser() {
repo.DeleteDevel()
}
if repo.UserSubsetOfDevel() {
repo.DeleteUser()
}
if repo.MasterSubsetOfDevel() {
}
if "user".IsSubset("devel") {
if repo("user") >= repo("devel") {
if repo.FirstIsIncludedInSecond("devel", "user") {
if repo.IsSubset("user", "devel") {
// delete user
} else {
// figure out what to do
}
*/
// reverts all repos back to the original master branches // reverts all repos back to the original master branches
// automatically deletes local devel and user branches // automatically deletes local devel and user branches
func doClean() error { func doClean() error {

View File

@ -13,7 +13,7 @@ import (
) )
func doCommit() error { func doCommit() error {
if argv.All { if argv.Commit.All {
found := me.forge.CheckDirty() found := me.forge.CheckDirty()
var newpatches bool var newpatches bool
for repo := range found.IterAll() { for repo := range found.IterAll() {

View File

@ -15,47 +15,47 @@ import (
// by default, it adds every repo // by default, it adds every repo
func doFind() *gitpb.Repos { func doFind() *gitpb.Repos {
if argv.List == nil { if argv.Show == nil {
return findAll() return findAll()
} }
if argv.List.Mine { if argv.Show.Mine {
return findMine() return findMine()
} }
if argv.List.Dirty { if argv.Show.Dirty != nil {
return me.forge.FindDirty() return me.forge.FindDirty()
} }
return findAll() return findAll()
} }
func (f *FindCmd) findRepos() *gitpb.Repos { func findRepos() *gitpb.Repos {
if f == nil { if argv.Show == nil {
return findMine() return findMine()
} }
if f.All { if argv.Show.All {
return findAll() return findAll()
} }
if f.Private { if argv.Show.Private {
return findPrivate() return findPrivate()
} }
if f.Mine { if argv.Show.Mine {
return findMine() return findMine()
} }
if f.Favorites { if argv.Show.Favorites {
return findFavorites() return findFavorites()
} }
if f.Dirty { if argv.Show.Dirty != nil {
return me.forge.FindDirty() return me.forge.FindDirty()
} }
if f.User { if argv.Show.User {
return findUser() return findUser()
} }

View File

@ -37,7 +37,7 @@ func doNormal() bool {
if count > 0 { if count > 0 {
log.Info("Some repos are not in a 'normal' state. error count =", count) log.Info("Some repos are not in a 'normal' state. error count =", count)
log.Info("TODO: list the repos here. forge patch repos?") log.Info("TODO: list the repos here. forge patch repos?")
dumpWorkRepos() showWorkRepos()
config.SetChanged("repos", true) config.SetChanged("repos", true)
return false return false
} }

View File

@ -60,7 +60,7 @@ func doPatchSubmit() error {
func doPatch() error { func doPatch() error {
if argv.Patch.Repos != nil { if argv.Patch.Repos != nil {
dumpWorkRepos() showWorkRepos()
return nil return nil
} }
@ -179,7 +179,7 @@ func doPatch() error {
// if nothing, show patches & dirty repos // if nothing, show patches & dirty repos
me.forge.Patchsets.PrintTable() me.forge.Patchsets.PrintTable()
dumpWorkRepos() showWorkRepos()
return nil return nil
} }
@ -189,7 +189,7 @@ func doPatch() error {
// - repos with awaiting master branch verions // - repos with awaiting master branch verions
// //
// return true if any are found // return true if any are found
func dumpWorkRepos() bool { func showWorkRepos() bool {
// always run dirty first // always run dirty first
me.forge.CheckDirtyQuiet() me.forge.CheckDirtyQuiet()
@ -207,7 +207,7 @@ func dumpWorkRepos() bool {
// returns bad if patches can not be applied // returns bad if patches can not be applied
// logic is not great here but it was a first pass // logic is not great here but it was a first pass
func dumpPatchset(pset *forgepb.Set) bool { func showPatchset(pset *forgepb.Set) bool {
// don't even bother to continue if we already know it's broken // don't even bother to continue if we already know it's broken
if pset.State == "BROKEN" { if pset.State == "BROKEN" {
log.Printf("Patchset Name: %-24s Author: %s <%s> IS BAD\n", pset.Name, pset.GetGitAuthorName(), pset.GetGitAuthorEmail()) log.Printf("Patchset Name: %-24s Author: %s <%s> IS BAD\n", pset.Name, pset.GetGitAuthorName(), pset.GetGitAuthorEmail())

View File

@ -36,7 +36,7 @@ func findCurrentPwdRepoOrDie() *gitpb.Repo {
func doTag() error { func doTag() error {
wd, _ := os.Getwd() wd, _ := os.Getwd()
if argv.Tag.List != nil { if argv.Show.Tag != nil {
repo := findCurrentPwdRepoOrDie() repo := findCurrentPwdRepoOrDie()
tagTablePB := makeTagTablePB(repo, repo.Tags) tagTablePB := makeTagTablePB(repo, repo.Tags)
@ -48,7 +48,7 @@ func doTag() error {
return nil return nil
} }
if argv.Tag.Delete != "" { if argv.Show.Tag.Delete != "" {
repo := FindRepoByFullPath(wd) repo := FindRepoByFullPath(wd)
if repo == nil { if repo == nil {
log.Info("Could not find repo:", wd) log.Info("Could not find repo:", wd)
@ -62,7 +62,7 @@ func doTag() error {
return log.Errorf("%s TAG DOES NOT EXIST %s", repo.FullPath, testtag) return log.Errorf("%s TAG DOES NOT EXIST %s", repo.FullPath, testtag)
} }
*/ */
testtag := argv.Tag.Delete testtag := argv.Show.Tag.Delete
if !argv.Force { if !argv.Force {
if !fhelp.QuestionUser(log.Sprintf("delete tag '%s'?", testtag)) { if !fhelp.QuestionUser(log.Sprintf("delete tag '%s'?", testtag)) {
return nil return nil

86
main.go
View File

@ -65,11 +65,6 @@ func main() {
okExit("") okExit("")
} }
if argv.BuildForge {
buildForge()
okExit("")
}
if argv.Checkout != nil { if argv.Checkout != nil {
if err := doCheckout(); err != nil { if err := doCheckout(); err != nil {
badExit(err) badExit(err)
@ -77,19 +72,26 @@ func main() {
okExit("") okExit("")
} }
if argv.Build != "" { /*
if err := doBuild(); err != nil { if argv.Show.BuildForge {
badExit(err) buildForge()
okExit("")
} }
okExit("")
}
if argv.Install != "" { if argv.Show.Build != "" {
if err := doInstall(); err != nil { if err := doBuild(); err != nil {
badExit(err) badExit(err)
}
okExit("")
} }
okExit("")
} if argv.Install != "" {
if err := doInstall(); err != nil {
badExit(err)
}
okExit("")
}
*/
if argv.Clean != nil { if argv.Clean != nil {
if err := doClean(); err != nil { if err := doClean(); err != nil {
@ -99,21 +101,6 @@ func main() {
okExit("") okExit("")
} }
if argv.Help != nil {
doHelp()
okExit("")
}
if argv.Dirty != nil {
doDirty()
okExit("")
}
if argv.Tag != nil {
doTag()
okExit("")
}
if argv.Normal != nil { if argv.Normal != nil {
if argv.Normal.On != nil { if argv.Normal.On != nil {
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL { if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
@ -166,10 +153,19 @@ func main() {
okExit("") okExit("")
} }
if argv.List != nil { if argv.Show != nil {
found := argv.List.findRepos() if argv.Show.Dirty != nil {
doDirty()
okExit("")
}
if argv.Show.Tag != nil {
doTag()
okExit("")
}
found := findRepos()
// print out the repos // print out the repos
if argv.List.Full { if argv.All {
me.forge.PrintHumanTableFull(found) me.forge.PrintHumanTableFull(found)
} else { } else {
me.forge.PrintHumanTable(found) me.forge.PrintHumanTable(found)
@ -196,7 +192,7 @@ func main() {
debug() // sits here forever debug() // sits here forever
} }
// got to the end with nothing to do (?) // got to the end with nothing to do (?)
if dumpWorkRepos() { if showWorkRepos() {
// found some repos at least // found some repos at least
} else { } else {
// every repo is in a really clean state. no extra files anywhere // every repo is in a really clean state. no extra files anywhere
@ -206,25 +202,3 @@ func main() {
} }
okExit("") okExit("")
} }
// keep this small
func doHelp() {
log.Info("")
log.Info("forge -h : to see the available options")
log.Info("forge --bash : will create a bash autocomplete file")
log.Info("forge : with no arguements, forge tries to load a GO GUI plugin")
log.Info(" : there are two GUI plugins. terminal & GTK")
log.Info("")
log.Info("forge list : shows a table of all your repos")
log.Info("forge checkout : checks out all your repos to the same branch")
log.Info(" : the default is your user branch")
log.Info("forge clean : reverts all repos to the master branch")
log.Info("forge dirty : show all repos git reports as dirty")
log.Info("")
okExit("")
}
func doHelpPatches() {
log.Info("TODO: ?")
okExit("")
}

0
test
View File