more ideas for command line options

This commit is contained in:
Jeff Carr 2024-12-27 03:39:53 -06:00
parent bdaa40c51f
commit 9818e8d1ee
4 changed files with 107 additions and 57 deletions

View File

@ -41,13 +41,13 @@ fix: install
forge --fix find --all
list-all: install
forge find --all
forge list --all
git-reset: install
forge --do-git-reset find --all
readonly: install
forge --do-list find --readonly
forge --list find --readonly
config: install
forge --config
@ -56,13 +56,13 @@ scan: install
forge do --scan
pull: install
forge do --pull
forge pull --mine
mine: install
forge --no-gui find --mine
forge list --mine
all: install
forge --no-gui find --all
forge list --all
patches: install
forge --patchset "from makefile"
@ -82,8 +82,10 @@ restart:
make private
user: install
forge find --all --user
forge --no-gui find --all
forge user
devel: install
forge devel --all
master: install
forge --master
forge master --all

21
argv.go
View File

@ -16,23 +16,24 @@ type FindCmd 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"`
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"`
GitPull *FindCmd `arg:"subcommand:pull" help:"run 'git pull'"`
Config bool `arg:"--config" help:"show your .config/forge/ settings"`
ListPatchSet bool `arg:"--list-patchset" help:"list patch sets"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
Delete string `arg:"--delete" help:"delete this repo"`
User bool `arg:"--user" help:"git checkout user"`
Devel bool `arg:"--devel" help:"git checkout devel"`
Master bool `arg:"--master" help:"git checkout master"`
URL string `arg:"--connect" help:"gowebd url"`
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"`
GitPull bool `arg:"--pull" help:"run 'git pull'"`
GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"`
Scan bool `arg:"--scan" help:"reload protobuf from .git/"`
Force bool `arg:"--force" help:"force redo things"`
Dirty bool `arg:"--dirty" help:"update git CheckDirty()"`
PatchSet string `arg:"--patchset" help:"make patch set"`
// List bool `arg:"--list" help:"just show a table of the current state"`
GitReset bool `arg:"--git-reset" help:"run 'git reset --hard'"`
Scan bool `arg:"--scan" help:"reload protobuf from .git/"`
Force bool `arg:"--force" help:"force redo things"`
Dirty bool `arg:"--dirty" help:"update git CheckDirty()"`
PatchSet string `arg:"--patchset" help:"make patch set"`
}
func (args) Version() string {

View File

@ -4,36 +4,59 @@ import (
"go.wit.com/log"
)
func findRepos() bool {
var done bool = false
if argv.Find != nil {
if argv.Find.All {
findAll()
done = true
}
if argv.Find.Private {
findPrivate()
done = true
}
if argv.Find.Mine {
findMine()
done = true
}
if argv.Find.Favorites {
findFavorites()
done = true
}
}
// this is the 'default' behavior when no command line arguments are given
// if no argv was set, select repos marked as 'mine'
if !done {
func (f *FindCmd) findRepos() {
if f == nil {
findMine()
done = true
return
}
return done
if f.All {
findAll(f)
return
}
if f.Private {
findPrivate()
return
}
if f.Mine {
findMine()
return
}
if f.Favorites {
findFavorites()
return
}
findMine()
}
func findRepos(fargv *FindCmd) {
if fargv == nil {
findMine()
return
}
if fargv.All {
findAll(fargv)
return
}
if fargv.Private {
findPrivate()
return
}
if fargv.Mine {
findMine()
return
}
if fargv.Favorites {
findFavorites()
return
}
findMine()
}
func findPrivate() {
@ -70,12 +93,13 @@ func findFavorites() {
}
}
func findAll() {
// func (f *FindCmd) findRepos() {
func findAll(fargv *FindCmd) {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
me.found.AppendUniqueGoPath(repo)
if me.forge.Config.IsReadOnly(repo.GetGoPath()) && !argv.Find.ReadOnly {
if me.forge.Config.IsReadOnly(repo.GetGoPath()) && !fargv.ReadOnly {
if repo.ReadOnly {
continue
}

41
main.go
View File

@ -41,13 +41,30 @@ func main() {
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
if argv.User {
if argv.User != nil {
me.forge.CheckoutUser()
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
argv.User.findRepos()
doCobol()
okExit("")
}
if argv.Master {
if argv.Devel != nil {
me.forge.CheckoutDevel()
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
argv.Devel.findRepos()
doCobol()
okExit("")
}
if argv.Master != nil {
me.forge.CheckoutMaster()
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
argv.Master.findRepos()
doCobol()
okExit("")
}
@ -75,37 +92,39 @@ func main() {
me.forge.ConfigPrintTable()
okExit("")
}
} else {
findRepos()
}
// okExit("")
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)
var done bool = false
if argv.Dirty {
findRepos(argv.Find)
doCheckDirty()
okExit("")
done = true
}
if argv.Scan {
findRepos(argv.Find)
doScan()
done = true
}
if argv.GitPull {
if argv.GitPull != nil {
argv.GitPull.findRepos()
doGitPull()
done = true
}
if argv.GitReset {
findRepos(argv.Find)
doGitReset()
done = true
}
if argv.List {
if argv.List != nil {
argv.List.findRepos()
// print out the repos
doCobol()
done = true
@ -136,7 +155,11 @@ func main() {
okExit("")
}
}
// open the gui
doGui()
// open the gui unless the user performed some other
// things from the command line
// basically, if you run just 'forge' it'll open the GUI
if !done {
doGui()
}
okExit("")
}