add some cmdline args

This commit is contained in:
Jeff Carr 2024-03-09 22:02:32 -06:00
parent 0f48d99b43
commit 0c8311467b
4 changed files with 104 additions and 1 deletions

View File

@ -3,6 +3,12 @@ VERSION = $(shell git describe --tags)
all: build all: build
./guireleaser ./guireleaser
single: build
./guireleaser go.wit.com/apps/go-clone --increment --release --reason "testing guireleaser" --dry-run
single-really-do-it: build
./guireleaser go.wit.com/apps/go-clone --increment --release --reason "testing guireleaser"
stderr: build stderr: build
echo "writing to /tmp/guireleaser.stderr" echo "writing to /tmp/guireleaser.stderr"
./guireleaser >/tmp/guireleaser.stderr 2>&1 ./guireleaser >/tmp/guireleaser.stderr 2>&1

28
argv.go Normal file
View File

@ -0,0 +1,28 @@
package main
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/
type args struct {
Repo string `arg:"positional" help:"go import path"`
Increment bool `arg:"--increment" help:"auto increment"`
Release bool `arg:"--release" help:"do a release an exit"`
DryRun bool `arg:"--dry-run" help:"don't actually do the release"`
Reason string `arg:"--reason" help:"tag message"`
}
func (a args) Description() string {
return `
Example usage:
guireleaser go.wit.com/apps/go-clone --increment --release --dry-run --reason "blerg"
This will pull down the go sources and
the repositories in the go.sum file using git clone`
}
func (args) Version() string {
return "go-clone " + VERSION
}

View File

@ -186,7 +186,7 @@ func globalDisplayOptions(box *gui.Node) {
repo.Status.IncrementMinorVersion("trying minor") repo.Status.IncrementMinorVersion("trying minor")
} }
}) })
grid.NewButton("ncrement changed repos", func() { grid.NewButton("increment changed repos", func() {
me.Disable() me.Disable()
for _, repo := range me.repos.View.AllRepos() { for _, repo := range me.repos.View.AllRepos() {
if whitelist(repo.GoPath()) { if whitelist(repo.GoPath()) {

69
main.go
View File

@ -4,16 +4,22 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/alexflint/go-arg"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/log" "go.wit.com/log"
) )
var VERSION string var VERSION string
var myargs args
func main() { func main() {
me = new(autoType) me = new(autoType)
// parse the command line
arg.MustParse(&myargs)
// save the ENV var here // save the ENV var here
me.releaseReasonS = os.Getenv("GUIRELEASE_REASON") me.releaseReasonS = os.Getenv("GUIRELEASE_REASON")
@ -87,6 +93,9 @@ func main() {
// TODO: should not really be necessary directly after init() // TODO: should not really be necessary directly after init()
me.repos.View.ScanRepositories() me.repos.View.ScanRepositories()
// the repo from the command line
var myrepo *repolist.RepoRow
// find myself. the guireleaser directory is used as a working scratchpad // find myself. the guireleaser directory is used as a working scratchpad
// for running go commands that can mess up the go.* files // for running go commands that can mess up the go.* files
for _, repo := range me.repos.View.AllRepos() { for _, repo := range me.repos.View.AllRepos() {
@ -95,6 +104,66 @@ func main() {
me.release.guireleaser = repo me.release.guireleaser = repo
} }
} }
if repo.GoPath() == myargs.Repo {
myrepo = repo
}
}
if myargs.Repo != "" {
me.mainWindow.Hide()
if myrepo == nil {
log.Info("could not find", myargs.Repo)
os.Exit(0)
}
log.Info("only going to do repo:", myrepo.GoPath())
tmp := myargs.Reason
if tmp == "" {
tmp = os.Getenv("GUIRELEASE_REASON")
}
if tmp == "" {
tmp = "made by guireleaser"
}
// increment all the versions
for _, repo := range me.repos.View.AllRepos() {
if whitelist(repo.GoPath()) {
continue
}
if repo.ReadOnly() {
continue
}
lasttag := repo.Status.LastTag()
if repo.Status.GetCurrentVersion() == lasttag {
log.Info("skipping unchanged repo", repo.Status.GoPath())
repo.Status.SetTargetVersion(lasttag)
continue
}
repo.Status.IncrementRevisionVersion("go-clone")
}
// rescan all the repos
me.repos.View.ScanRepositories()
myrepo.Status.MakeRedomod()
myrepo.Status.IncrementRevisionVersion(tmp)
_, err := me.repos.View.CheckValidGoSum(myrepo)
if err != nil {
log.Info("go mod tidy not ok", err)
return
}
if !checkValidGoSum(myrepo) {
log.Info("go.sum checks failed")
os.Exit(0)
}
setCurrentRepo(myrepo, "should be good to release", "pretty sure")
log.Info("DO THE RELEASE HERE")
log.Info("going to release", myrepo.GoPath(), "as version", myrepo.Status.GetTargetVersion())
if myargs.DryRun {
log.Info("--dry-run == true")
} else {
doRelease()
}
os.Exit(0)
} }
if me.release.guireleaser == nil { if me.release.guireleaser == nil {