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
import (
"fmt"
"os"
"go.wit.com/lib/gui/prep"
"go.wit.com/log"
)
/*
@ -17,27 +17,36 @@ import (
var argv args
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'"`
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"`
Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
Dirty *DirtyCmd `arg:"subcommand:dirty" help:"show dirty git repos"`
GitFetch *FindCmd `arg:"subcommand:fetch" help:"run 'git fetch master'"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"`
List *FindCmd `arg:"subcommand:list" help:"print a table of the current repos"`
Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"`
Normal *NormalCmd `arg:"subcommand:normal" help:"set every repo to the default state for software development"`
Patch *PatchCmd `arg:"subcommand:patch" help:"make patchsets"`
Pull *PullCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Tag *TagCmd `arg:"subcommand:tag" help:"manage git tags"`
URL string `arg:"--connect" help:"forge url"`
All bool `arg:"--all" help:"git commit --all"`
Build string `arg:"--build" help:"build a repo"`
Install string `arg:"--install" help:"install a repo"`
BuildForge bool `arg:"--forge-rebuild" help:"download and rebuild forge"`
Force bool `arg:"--force" help:"try to strong arm things"`
Verbose bool `arg:"--verbose" help:"show more output"`
Checkout *CheckoutCmd `arg:"subcommand:checkout" help:"switch branches using 'git checkout'"`
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"`
Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"`
Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"`
Normal *NormalCmd `arg:"subcommand:normal" help:"set every repo to the default state for software development"`
Patch *PatchCmd `arg:"subcommand:patch" help:"make patchsets"`
Pull *PullCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Show *ShowCmd `arg:"subcommand:show" help:"print out things"`
All bool `arg:"--all" help:"git commit --all"`
Force bool `arg:"--force" help:"try to strong-arm things"`
Verbose bool `arg:"--verbose" help:"show more output"`
}
type ShowCmd struct {
Dirty *EmptyCmd `arg:"subcommand:dirty" help:"show dirty git repos"`
List *EmptyCmd `arg:"subcommand:list" help:"print a table of the current repos"`
Tag *TagCmd `arg:"subcommand:tag" help:"manage git tags"`
Build string `arg:"--build" help:"build a repo"`
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 {
@ -49,7 +58,8 @@ type NormalCmd 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
@ -103,6 +113,18 @@ type ConfigAddCmd struct {
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"`
@ -111,37 +133,29 @@ type ConfigCmd struct {
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 {
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 {
// doHelp()
return `
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
func DoAutoComplete(pb *prep.Auto) {
switch pb.Cmd {
case "checkout":
pb.Autocomplete2("devel master user")
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")
case "show":
pb.SubCommand(pb.Cmd)
default:
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 {
pb.Autocomplete2("list checkout clean commit dirty normal merge tag")
pb.SubCommand(pb.Cmd)
}
}
os.Exit(0)

View File

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

View File

@ -29,6 +29,30 @@ func checkRemoteBranches(repo *gitpb.Repo) error {
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
// automatically deletes local devel and user branches
func doClean() error {

View File

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

View File

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

View File

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

View File

@ -60,7 +60,7 @@ func doPatchSubmit() error {
func doPatch() error {
if argv.Patch.Repos != nil {
dumpWorkRepos()
showWorkRepos()
return nil
}
@ -179,7 +179,7 @@ func doPatch() error {
// if nothing, show patches & dirty repos
me.forge.Patchsets.PrintTable()
dumpWorkRepos()
showWorkRepos()
return nil
}
@ -189,7 +189,7 @@ func doPatch() error {
// - repos with awaiting master branch verions
//
// return true if any are found
func dumpWorkRepos() bool {
func showWorkRepos() bool {
// always run dirty first
me.forge.CheckDirtyQuiet()
@ -207,7 +207,7 @@ func dumpWorkRepos() bool {
// returns bad if patches can not be applied
// 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
if pset.State == "BROKEN" {
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 {
wd, _ := os.Getwd()
if argv.Tag.List != nil {
if argv.Show.Tag != nil {
repo := findCurrentPwdRepoOrDie()
tagTablePB := makeTagTablePB(repo, repo.Tags)
@ -48,7 +48,7 @@ func doTag() error {
return nil
}
if argv.Tag.Delete != "" {
if argv.Show.Tag.Delete != "" {
repo := FindRepoByFullPath(wd)
if repo == nil {
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)
}
*/
testtag := argv.Tag.Delete
testtag := argv.Show.Tag.Delete
if !argv.Force {
if !fhelp.QuestionUser(log.Sprintf("delete tag '%s'?", testtag)) {
return nil

86
main.go
View File

@ -65,11 +65,6 @@ func main() {
okExit("")
}
if argv.BuildForge {
buildForge()
okExit("")
}
if argv.Checkout != nil {
if err := doCheckout(); err != nil {
badExit(err)
@ -77,19 +72,26 @@ func main() {
okExit("")
}
if argv.Build != "" {
if err := doBuild(); err != nil {
badExit(err)
/*
if argv.Show.BuildForge {
buildForge()
okExit("")
}
okExit("")
}
if argv.Install != "" {
if err := doInstall(); err != nil {
badExit(err)
if argv.Show.Build != "" {
if err := doBuild(); err != nil {
badExit(err)
}
okExit("")
}
okExit("")
}
if argv.Install != "" {
if err := doInstall(); err != nil {
badExit(err)
}
okExit("")
}
*/
if argv.Clean != nil {
if err := doClean(); err != nil {
@ -99,21 +101,6 @@ func main() {
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.On != nil {
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
@ -166,10 +153,19 @@ func main() {
okExit("")
}
if argv.List != nil {
found := argv.List.findRepos()
if argv.Show != nil {
if argv.Show.Dirty != nil {
doDirty()
okExit("")
}
if argv.Show.Tag != nil {
doTag()
okExit("")
}
found := findRepos()
// print out the repos
if argv.List.Full {
if argv.All {
me.forge.PrintHumanTableFull(found)
} else {
me.forge.PrintHumanTable(found)
@ -196,7 +192,7 @@ func main() {
debug() // sits here forever
}
// got to the end with nothing to do (?)
if dumpWorkRepos() {
if showWorkRepos() {
// found some repos at least
} else {
// every repo is in a really clean state. no extra files anywhere
@ -206,25 +202,3 @@ func main() {
}
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