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
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:
@#GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.VERSION=${VERSION}"
@ -45,7 +46,7 @@ reset:
# clear your terminal
reset
gocui: build
gui-gocui: build
reset
./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
## debian packages
Debian packages are at mirrors.wit.com
## TODO:
* use protobuf

View File

@ -6,6 +6,8 @@ package main
this enables command line options from other packages like 'gui' and 'log'
*/
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"`
@ -28,5 +30,5 @@ This will recursively clone the app and all the build requirements:
}
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"
)
var Version string
// sent from -ldflags
var VERSION string
var rv *repolist.RepoList
var myargs args
func main() {
pp := arg.MustParse(&myargs)
pp := arg.MustParse(&argv)
if myargs.Repo == "" {
if argv.Repo == "" {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
if myargs.Repo == "version" {
log.Info(Version)
os.Exit(0)
}
if myargs.Repo == "version" || myargs.Repo == "help" || myargs.Repo == "?" {
// for very new users or users unfamilar with the command line, this may help them
if argv.Repo == "version" || argv.Repo == "help" || argv.Repo == "?" {
pp.WriteHelp(os.Stdout)
os.Exit(0)
}
@ -52,13 +48,21 @@ func main() {
rv = repolist.AutotypistView(b)
os.Setenv("REPO_AUTO_CLONE", "true")
newr, err := rv.NewRepo(myargs.Repo)
newr, err := rv.NewRepo(argv.Repo)
if err != nil {
log.Info("could not download:", err)
os.Exit(-1)
}
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")
for _, path := range repostatus.ScanGitDirectories(wdir) {
gopath := strings.TrimPrefix(path, wdir)
@ -68,7 +72,7 @@ func main() {
}
godep := newr.Status.GetGoDeps()
if myargs.Recursive {
if argv.Recursive {
for gopath, version := range godep {
repo, err := rv.NewRepo(gopath)
if err != nil {
@ -88,8 +92,8 @@ func main() {
}
log.Info("Total repositories:", count)
log.Info("Finished go-clone for", myargs.Repo)
if !myargs.NoWork {
log.Info("Finished go-clone for", argv.Repo)
if !argv.NoWork {
log.Info("Creating", wdir+"/go.work")
rv.MakeGoWork()
shell.RunPath(wdir, []string{"go", "work", "use"})
@ -105,7 +109,7 @@ func main() {
// look for or make a go.work file
// otherwise use ~/go/src
func findWorkFile() (string, error) {
if myargs.GoSrc {
if argv.GoSrc {
// user put --go-src on the command line so use ~/go/src
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 ! myargs.NoWork {
if !argv.NoWork {
pwd, err = os.Getwd()
newpwd := filepath.Join(pwd, "work")
shell.Mkdir(newpwd)