add --auto-work option to generate go.work files

This commit is contained in:
Jeff Carr 2024-11-15 09:29:49 -06:00
parent bef6d6c911
commit f8bef3081c
2 changed files with 14 additions and 16 deletions

14
argv.go
View File

@ -9,13 +9,13 @@ package main
var argv args
type args struct {
Repo string `arg:"positional" help:"go import path"`
NoWork bool `arg:"--no-work" default:"true" help:"do not make or modify the go.work file"`
GoSrc bool `arg:"--go-src" default:"true" help:"only work in ~/go/src"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Recursive bool `arg:"--recursive" default:"false" help:"resursively clone all dependencies"`
Pull bool `arg:"--pull" default:"false" help:"run 'git pull' on all your repos"`
// Fetch bool `arg:"--fetch" default:"false" help:"run 'git fetch' on all your repos"`
Repo string `arg:"positional" help:"go import path"`
AutoWork bool `arg:"--auto-work" default:"false" help:"auto recreate the go.work file"`
GoSrc bool `arg:"--go-src" default:"true" help:"only work in ~/go/src"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Recursive bool `arg:"--recursive" default:"false" help:"resursively clone all dependencies"`
Pull bool `arg:"--git-pull" default:"false" help:"run 'git pull' on all your repos"`
// Fetch bool `arg:"--git-fetch" default:"false" help:"run 'git fetch' on all your repos"`
}
func (a args) Description() string {

16
main.go
View File

@ -68,7 +68,7 @@ func main() {
} else {
trycount += 1
log.Info("actually run: git pull:", repo.Status.Path())
if result := repo.Status.Run(pull); result.Error != nil {
if result := shell.PathRunRealtime(repo.Status.Path(), pull); result.Error != nil {
log.Info("git pull error:", result.Error)
errcount += 1
}
@ -78,8 +78,8 @@ func main() {
os.Exit(0)
}
// if the user didn't provide a repo, stop here
if argv.Repo == "" {
// if the user didn't provide a repo, stop here unless --git-pull
if argv.Repo == "" || argv.Pull {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
@ -93,11 +93,9 @@ func main() {
newr.Status.MakeRedomod()
fullgitdir = filepath.Join(wdir, argv.Repo, ".git")
if shell.IsDir(fullgitdir) {
if ! argv.Recursive {
log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
os.Exit(0)
}
if ! shell.IsDir(fullgitdir) {
log.Info("repo cloned failed", filepath.Join(wdir, argv.Repo))
os.Exit(-1)
}
log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo))
@ -134,7 +132,7 @@ func main() {
log.Info("Total repositories:", count)
log.Info("Finished go-clone for", argv.Repo)
if !argv.NoWork {
if argv.AutoWork {
log.Info("Creating", wdir+"/go.work")
rv.MakeGoWork()
shell.PathRun(wdir, []string{"go", "work", "use"})