new forge init()

This commit is contained in:
Jeff Carr 2025-09-11 03:27:49 -05:00
parent 54811a5bc1
commit d19f4a8911
4 changed files with 50 additions and 14 deletions

View File

@ -1,7 +1,7 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
run: install build-darwin build-darwin-arm64 build-windows
run: install
go-clone --version
vet:
@ -51,7 +51,7 @@ nocui: build
clean:
rm -f go.*
-rm go-clone
-rm go-clone*
go-mod-clean purge
# this will test the golang.org/x -> googlesource override

20
argv.go
View File

@ -1,5 +1,10 @@
package main
import (
"fmt"
"os"
)
/*
this parses the command line arguements
@ -31,3 +36,18 @@ Examples:
go-clone go.wit.com/apps/go-clone # 'git clone' go-clone
`
}
func (a args) DoAutoComplete(argv []string) {
switch argv[0] {
case "checkout":
fmt.Println("user devel master ")
case "--recursive":
fmt.Println("true false")
default:
if argv[0] == ARGNAME {
// list the subcommands here
fmt.Println("--dry-run --recursive --work")
}
}
os.Exit(0)
}

19
config.go Normal file
View File

@ -0,0 +1,19 @@
package main
import (
"go.wit.com/lib/config"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
// sent via -ldflags
func configInit() *forgepb.ForgeConfigs {
configs := new(forgepb.ForgeConfigs)
err := config.ConfigLoad(configs, "forge", "forge")
if err != nil {
log.Info("This tool requires your repos be scanned by forge first")
badExit(err)
}
return configs
}

21
main.go
View File

@ -4,6 +4,7 @@ import (
"os"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@ -13,6 +14,8 @@ import (
var VERSION string
var BUILDTIME string
var ARGNAME string = "go-clone"
var pp *arg.Parser
var forge *forgepb.Forge
@ -20,20 +23,14 @@ var workingRepo *gitpb.Repo
func main() {
log.Info("go-clone version", VERSION, "built on", BUILDTIME)
// command line parsing & handling
prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: make this: prep.Bash(argv)
pp = arg.MustParse(&argv)
// for very new users or users unfamilar with the command line, this may help them
if argv.Repo == "help" || argv.Repo == "?" {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
if argv.Repo == "version" {
log.Info(argv.Version())
os.Exit(0)
}
// this package helps scan git repos
forge = forgepb.Init()
// read in forge info
cfg := configInit()
forge = forgepb.InitFromConfig(cfg)
var err error
// attempt to clone, returns *gitpb.Repo