autotypist/checkout.go

115 lines
2.5 KiB
Go

package main
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"context"
"fmt"
"github.com/destel/rill"
"github.com/destel/rill/mockapi"
"go.wit.com/lib/gui/repolist"
"go.wit.com/log"
)
// okay
func checkoutDevel() bool {
log.Info("running git checkout devel everwhere")
var failed int = 0
var count int = 0
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
count += 1
// don't switch branches on readonly repos
if me.forge.IsReadOnly(repo.GoPath()) {
continue
}
if repo.Status.CheckoutDevel() {
// checkout ok
} else {
failed += 1
}
}
log.Info("Ran git checkout in", count, "repos. failure count =", failed)
return true
}
// https://news.ycombinator.com/item?id=42237166
// https://github.com/destel/rill
// https://pkg.go.dev/github.com/destel/rill
func rillMockapi() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Convert a slice of user IDs into a channel
ids := rill.FromSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, nil)
// Read users from the API.
// Concurrency = 3
users := rill.Map(ids, 3, func(id int) (*mockapi.User, error) {
return mockapi.GetUser(ctx, id)
})
// Activate users.
// Concurrency = 2
err := rill.ForEach(users, 2, func(u *mockapi.User) error {
if u.IsActive {
fmt.Printf("User %d is already active\n", u.ID)
return nil
}
u.IsActive = true
err := mockapi.SaveUser(ctx, u)
if err != nil {
return err
}
fmt.Printf("User saved: %+v\n", u)
return nil
})
// Handle errors
fmt.Println("Error:", err)
}
// rediculously wrong for the purposes of understanding rill
// which, seems to be awesome. long live rill
func rillGitPull() {
// todo: wrap my head around what this could be for
// ctx, cancel := context.WithCancel(context.Background())
// defer cancel()
var gopaths []string
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
gopaths = append(gopaths, repo.GoPath())
}
// Convert a slice of user IDs into a channel
ids := rill.FromSlice(gopaths, nil)
// Read users from the API.
// Concurrency = 20
users := rill.Map(ids, 20, func(id string) (*repolist.RepoRow, error) {
return me.repos.View.FindByName(id), nil
})
// Activate users.
// Concurrency = 10
err := rill.ForEach(users, 10, func(repo *repolist.RepoRow) error {
fmt.Printf("Repo found : %s\n", repo.GoPath())
repo.Run([]string{"git", "pull"})
return nil
})
// Handle errors
fmt.Println("Error:", err)
}