rename to 'argv'; use standard -ldflags

This commit is contained in:
Jeff Carr 2024-11-07 07:03:51 -06:00
parent d576aa8a25
commit 5abf602bf7
4 changed files with 30 additions and 19 deletions

View File

@ -23,7 +23,8 @@ no-gui: build
./go-clone --no-gui ./go-clone --no-gui
build: build:
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}" GO111MODULE=off go build -v \
-ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}"
build-go-1.21: build-go-1.21:
@#GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.VERSION=${VERSION}" @#GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.VERSION=${VERSION}"
@ -45,7 +46,7 @@ reset:
# clear your terminal # clear your terminal
reset reset
gocui: build gui-gocui: build
reset reset
./go-clone --gui gocui >/tmp/witgui.log.stderr 2>&1 ./go-clone --gui gocui >/tmp/witgui.log.stderr 2>&1

View File

@ -16,6 +16,10 @@ Or to recursively clone all the build dependancies:
go-clone --recursive go.wit.com/apps/go-clone go-clone --recursive go.wit.com/apps/go-clone
## debian packages
Debian packages are at mirrors.wit.com
## TODO: ## TODO:
* use protobuf * use protobuf

View File

@ -6,6 +6,8 @@ package main
this enables command line options from other packages like 'gui' and 'log' this enables command line options from other packages like 'gui' and 'log'
*/ */
var argv args
type args struct { type args struct {
Repo string `arg:"positional" help:"go import path"` 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"` NoWork bool `arg:"--no-work" default:"true" help:"do not make or modify the go.work file"`
@ -28,5 +30,5 @@ This will recursively clone the app and all the build requirements:
} }
func (args) Version() string { func (args) Version() string {
return "go-clone " + Version return "go-clone " + VERSION
} }

36
main.go
View File

@ -14,25 +14,21 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
var Version string // sent from -ldflags
var VERSION string
var rv *repolist.RepoList var rv *repolist.RepoList
var myargs args
func main() { func main() {
pp := arg.MustParse(&myargs) pp := arg.MustParse(&argv)
if myargs.Repo == "" { if argv.Repo == "" {
pp.WriteHelp(os.Stdout) pp.WriteHelp(os.Stdout)
os.Exit(0) os.Exit(0)
} }
if myargs.Repo == "version" { // for very new users or users unfamilar with the command line, this may help them
log.Info(Version) if argv.Repo == "version" || argv.Repo == "help" || argv.Repo == "?" {
os.Exit(0)
}
if myargs.Repo == "version" || myargs.Repo == "help" || myargs.Repo == "?" {
pp.WriteHelp(os.Stdout) pp.WriteHelp(os.Stdout)
os.Exit(0) os.Exit(0)
} }
@ -52,13 +48,21 @@ func main() {
rv = repolist.AutotypistView(b) rv = repolist.AutotypistView(b)
os.Setenv("REPO_AUTO_CLONE", "true") os.Setenv("REPO_AUTO_CLONE", "true")
newr, err := rv.NewRepo(myargs.Repo) newr, err := rv.NewRepo(argv.Repo)
if err != nil { if err != nil {
log.Info("could not download:", err) log.Info("could not download:", err)
os.Exit(-1) os.Exit(-1)
} }
newr.Status.MakeRedomod() newr.Status.MakeRedomod()
fullgitdir := filepath.Join(wdir, argv.Repo, ".git")
if shell.IsDir(fullgitdir) {
log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
os.Exit(0)
}
log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo))
// rv.NewRepo("go.wit.com/apps/helloworld") // rv.NewRepo("go.wit.com/apps/helloworld")
for _, path := range repostatus.ScanGitDirectories(wdir) { for _, path := range repostatus.ScanGitDirectories(wdir) {
gopath := strings.TrimPrefix(path, wdir) gopath := strings.TrimPrefix(path, wdir)
@ -68,7 +72,7 @@ func main() {
} }
godep := newr.Status.GetGoDeps() godep := newr.Status.GetGoDeps()
if myargs.Recursive { if argv.Recursive {
for gopath, version := range godep { for gopath, version := range godep {
repo, err := rv.NewRepo(gopath) repo, err := rv.NewRepo(gopath)
if err != nil { if err != nil {
@ -88,8 +92,8 @@ func main() {
} }
log.Info("Total repositories:", count) log.Info("Total repositories:", count)
log.Info("Finished go-clone for", myargs.Repo) log.Info("Finished go-clone for", argv.Repo)
if !myargs.NoWork { if !argv.NoWork {
log.Info("Creating", wdir+"/go.work") log.Info("Creating", wdir+"/go.work")
rv.MakeGoWork() rv.MakeGoWork()
shell.RunPath(wdir, []string{"go", "work", "use"}) shell.RunPath(wdir, []string{"go", "work", "use"})
@ -105,7 +109,7 @@ func main() {
// look for or make a go.work file // look for or make a go.work file
// otherwise use ~/go/src // otherwise use ~/go/src
func findWorkFile() (string, error) { func findWorkFile() (string, error) {
if myargs.GoSrc { if argv.GoSrc {
// user put --go-src on the command line so use ~/go/src // user put --go-src on the command line so use ~/go/src
return useGoSrc() return useGoSrc()
} }
@ -120,7 +124,7 @@ func findWorkFile() (string, error) {
} }
// if the user added '--work' on the cmdline, make a work directory and init the go.work file // if the user added '--work' on the cmdline, make a work directory and init the go.work file
if ! myargs.NoWork { if !argv.NoWork {
pwd, err = os.Getwd() pwd, err = os.Getwd()
newpwd := filepath.Join(pwd, "work") newpwd := filepath.Join(pwd, "work")
shell.Mkdir(newpwd) shell.Mkdir(newpwd)