forged init
This commit is contained in:
parent
3d3a07c194
commit
0d9fe58e57
2
Makefile
2
Makefile
|
@ -5,8 +5,8 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
# ./forged pull
|
# ./forged pull
|
||||||
FORGE_GOSRC=/home/forge ./forged list
|
|
||||||
# ./forged list
|
# ./forged list
|
||||||
|
./forged init
|
||||||
|
|
||||||
build: goimports
|
build: goimports
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
|
|
1
argv.go
1
argv.go
|
@ -14,6 +14,7 @@ var argv args
|
||||||
type args struct {
|
type args struct {
|
||||||
Pull *EmptyCmd `arg:"subcommand:pull" help:"list the repos"`
|
Pull *EmptyCmd `arg:"subcommand:pull" help:"list the repos"`
|
||||||
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
|
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
|
||||||
|
Init *EmptyCmd `arg:"subcommand:init" help:"list the repos"`
|
||||||
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
Port int `arg:"--port" default:"2520" help:"port to run on"`
|
||||||
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
|
Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"`
|
||||||
}
|
}
|
||||||
|
|
66
doPull.go
66
doPull.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
@ -74,11 +75,73 @@ func tryGitClone(repo *gitpb.Repo, dir string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func doList() {
|
func initForged() *forgepb.Forge {
|
||||||
log.Info("do pull here")
|
log.Info("do pull here")
|
||||||
dirs, err := scanForgedDir(FORGEDIR)
|
dirs, err := scanForgedDir(FORGEDIR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badExit(err)
|
badExit(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
os.Chdir(FORGEDIR)
|
||||||
|
forge := forgepb.InitPB()
|
||||||
|
log.Printf("forged has %d repos\n", forge.Repos.Len())
|
||||||
|
// forge.PrintHumanTable(forge.Repos)
|
||||||
|
|
||||||
|
for _, dir := range dirs {
|
||||||
|
oldr, err := readGitPB(dir)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("readGitPB() failed", dir, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fullpath := filepath.Join(dir, "git.clone")
|
||||||
|
|
||||||
|
if check := forge.Repos.FindByFullPath(fullpath); check != nil {
|
||||||
|
// log.Info(oldr.Namespace, fullpath, "already added")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// check to see if 'git clone' has already been run
|
||||||
|
_, err = os.Stat(fullpath)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
log.Info("repo needs cloning:", oldr.Namespace, oldr.FullPath, dir)
|
||||||
|
} else {
|
||||||
|
log.Info("repo is already cloned", dir, oldr.Namespace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return forge
|
||||||
|
}
|
||||||
|
|
||||||
|
func verifyForged(f *forgepb.Forge) {
|
||||||
|
var changed bool = false
|
||||||
|
for repo := range f.Repos.IterAll() {
|
||||||
|
if strings.HasPrefix(repo.GetFullPath(), os.Getenv("FORGE_GOSRC")) {
|
||||||
|
// log.Info(os.Getenv("FORGE_GOSRC"), repo.GetFullPath())
|
||||||
|
} else {
|
||||||
|
log.Info("not here", os.Getenv("FORGE_GOSRC"), repo.GetFullPath())
|
||||||
|
f.Repos.Delete(repo)
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if changed {
|
||||||
|
f.Repos.ConfigSave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doInit() *forgepb.Forge {
|
||||||
|
forge := initForged()
|
||||||
|
|
||||||
|
verifyForged(forge)
|
||||||
|
|
||||||
|
return forge
|
||||||
|
}
|
||||||
|
|
||||||
|
func doList() any {
|
||||||
|
log.Info("do pull here")
|
||||||
|
dirs, err := scanForgedDir(FORGEDIR)
|
||||||
|
if err != nil {
|
||||||
|
badExit(err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
os.Chdir(FORGEDIR)
|
os.Chdir(FORGEDIR)
|
||||||
forge := forgepb.InitPB()
|
forge := forgepb.InitPB()
|
||||||
|
@ -133,4 +196,5 @@ func doList() {
|
||||||
forge.PrintHumanTable(forge.Repos)
|
forge.PrintHumanTable(forge.Repos)
|
||||||
forge.Repos.ConfigSave()
|
forge.Repos.ConfigSave()
|
||||||
okExit("")
|
okExit("")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
4
exit.go
4
exit.go
|
@ -9,6 +9,10 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func exit(thing any) {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
func okExit(thing string) {
|
func okExit(thing string) {
|
||||||
if thing != "" {
|
if thing != "" {
|
||||||
log.Info("forge exit:", thing, "ok")
|
log.Info("forge exit:", thing, "ok")
|
||||||
|
|
15
main.go
15
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -26,11 +27,21 @@ func main() {
|
||||||
if argv.Hostname != "" {
|
if argv.Hostname != "" {
|
||||||
HOSTNAME = argv.Hostname
|
HOSTNAME = argv.Hostname
|
||||||
}
|
}
|
||||||
|
// the default forged dir is /home/forge
|
||||||
|
if os.Getenv("FORGE_GOSRC") == "" {
|
||||||
|
os.Setenv("FORGE_GOSRC", "/home/forge")
|
||||||
|
}
|
||||||
|
|
||||||
if argv.List != nil {
|
if argv.Init != nil {
|
||||||
doList()
|
doInit()
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if argv.List != nil {
|
||||||
|
exit(doList())
|
||||||
|
okExit("")
|
||||||
|
}
|
||||||
|
|
||||||
// forge = forgepb.Init()
|
// forge = forgepb.Init()
|
||||||
if argv.Pull != nil {
|
if argv.Pull != nil {
|
||||||
doPull()
|
doPull()
|
||||||
|
|
Loading…
Reference in New Issue