everything successfully in repostatus package
code now uses 'hidden' widgets add go.* remvoe old code status is maybe done skips non-existent repos Signed-off-by: Jeff Carr <jcarr@wit.com> Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
e26413e636
commit
b700881b43
|
@ -2,3 +2,4 @@
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!Makefile
|
!Makefile
|
||||||
!*.go
|
!*.go
|
||||||
|
!go.*
|
||||||
|
|
143
git.go
143
git.go
|
@ -1,143 +0,0 @@
|
||||||
// This is a simple example
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
|
||||||
|
|
||||||
// "go.wit.com/gui/gui"
|
|
||||||
// "go.wit.com/gui/gadgets"
|
|
||||||
// "go.wit.com/apps/control-panel-dns/smartwindow"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (r *repo) checkoutBranch(branch string) {
|
|
||||||
if r.checkDirty() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
out := run(r.path, "git", "checkout " + branch)
|
|
||||||
log.Warn(r.path, "git checkout " + branch, "returned", out)
|
|
||||||
|
|
||||||
realname := r.getCurrentBranchName()
|
|
||||||
realversion := r.getCurrentBranchVersion()
|
|
||||||
log.Warn(r.path, "realname =", realname, "realversion =", realversion)
|
|
||||||
if realname == "jcarr" {
|
|
||||||
r.jcarrVersion.Set(realversion)
|
|
||||||
}
|
|
||||||
if realname == "devel" {
|
|
||||||
r.develVersion.Set(realversion)
|
|
||||||
}
|
|
||||||
if realname == "master" {
|
|
||||||
r.masterVersion.Set(realversion)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) getBranch() {
|
|
||||||
out := run(r.path, "git", "branch --show-current")
|
|
||||||
r.bLabel.SetText(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) checkDirty() bool {
|
|
||||||
if r.path == "" {
|
|
||||||
log.Warn("disable spaceholders")
|
|
||||||
r.cButton.Disable()
|
|
||||||
r.pButton.Disable()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
out := run(r.path, "git", "diff-index HEAD")
|
|
||||||
if out == "" {
|
|
||||||
r.dirtyLabel.SetText("")
|
|
||||||
r.pButton.SetText("scan")
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
r.dirtyLabel.SetText("dirty")
|
|
||||||
r.pButton.SetText("scan")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) getLastTagVersion() string {
|
|
||||||
out := run(r.path, "git", "rev-list --tags --max-count=1")
|
|
||||||
out = strings.TrimSpace(out)
|
|
||||||
r.lasttagrev = out
|
|
||||||
|
|
||||||
lastreal := "describe --tags " + out
|
|
||||||
// out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
|
|
||||||
out = run(r.path, "git", lastreal)
|
|
||||||
r.lasttag = out
|
|
||||||
r.lastLabel.SetText(out)
|
|
||||||
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) getCurrentBranchName() string {
|
|
||||||
out := run(r.path, "git", "branch --show-current")
|
|
||||||
r.bLabel.SetText(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) getCurrentBranchVersion() string {
|
|
||||||
out := run(r.path, "git", "describe --tags")
|
|
||||||
log.Warn("getCurrentBranchVersion", out)
|
|
||||||
r.vLabel.SetText(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) populateTags() {
|
|
||||||
r.tags = listFiles(fullpath(r.path + "/.git/refs/tags"))
|
|
||||||
for _, tag := range r.tags {
|
|
||||||
r.tagsDrop.AddText(tag)
|
|
||||||
}
|
|
||||||
// r.tagsDrop.SetText(r.lasttag)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) scan() {
|
|
||||||
|
|
||||||
r.getLastTagVersion()
|
|
||||||
r.getCurrentBranchName()
|
|
||||||
r.getCurrentBranchVersion()
|
|
||||||
r.populateTags()
|
|
||||||
if r.checkDirty() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.checkoutBranch("master")
|
|
||||||
r.checkoutBranch("devel")
|
|
||||||
r.checkoutBranch("jcarr")
|
|
||||||
|
|
||||||
lasttag := r.lastLabel.GetText()
|
|
||||||
master := r.masterVersion.GetText()
|
|
||||||
devel := r.develVersion.GetText()
|
|
||||||
jcarr := r.jcarrVersion.GetText()
|
|
||||||
|
|
||||||
log.Warn("")
|
|
||||||
log.Warn("lasttag =", lasttag)
|
|
||||||
log.Warn("master =", master)
|
|
||||||
log.Warn("devel =", devel)
|
|
||||||
log.Warn("jcarr =", jcarr)
|
|
||||||
|
|
||||||
r.dirtyLabel.SetText("garbage")
|
|
||||||
|
|
||||||
if devel != master {
|
|
||||||
log.Warn("devel version != master version", devel, "vs", master)
|
|
||||||
r.dirtyLabel.SetText("merge")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if lasttag != master {
|
|
||||||
log.Warn("last tag rev != master version", lasttag, "vs", master)
|
|
||||||
r.dirtyLabel.SetText("merge")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if lasttag == jcarr {
|
|
||||||
log.Warn("last tag rev == jcarr version", lasttag, "vs", jcarr)
|
|
||||||
r.dirtyLabel.SetText("GOOD")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkrepos() {
|
|
||||||
for i, r := range allrepos {
|
|
||||||
log.Warn("scannning", i, r.path)
|
|
||||||
r.scan()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
module go.wit.com/apps/myrepos
|
||||||
|
|
||||||
|
go 1.21.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
go.wit.com/apps/control-panel-dns v0.12.1
|
||||||
|
go.wit.com/gui/gadgets v0.10.3
|
||||||
|
go.wit.com/gui/gadgets/repostatus v0.0.0-20240110012216-abd9781d8a60
|
||||||
|
go.wit.com/gui/gui v0.12.4
|
||||||
|
go.wit.com/log v0.5.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/alexflint/go-scalar v1.2.0 // indirect
|
||||||
|
go.wit.com/dev/alexflint/go-arg v1.4.4 // indirect
|
||||||
|
go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93 // indirect
|
||||||
|
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,27 @@
|
||||||
|
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
|
||||||
|
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
go.wit.com/apps/control-panel-dns v0.12.1 h1:FBaNeSPIoyBXWir4ggxFiaBpHtGnbOj+GGHbK3Rpbo0=
|
||||||
|
go.wit.com/apps/control-panel-dns v0.12.1/go.mod h1:y+DRqorB3K/xAiDSil5cCVUalsJzMdUQuK9HambO0fQ=
|
||||||
|
go.wit.com/dev/alexflint/go-arg v1.4.4 h1:n7sDAPpaxzZ/nGKyVRj1Y/V0H18frfqSwI8yFe/9BGc=
|
||||||
|
go.wit.com/dev/alexflint/go-arg v1.4.4/go.mod h1:td08jpeZ4vQ/Bu870In78YE2QRrNXhxvY1A34hC7qFo=
|
||||||
|
go.wit.com/gui/gadgets v0.10.3 h1:sL1GULM8Aedch3kSBdm4XuYMz/TfJ+pPeha/927/pGU=
|
||||||
|
go.wit.com/gui/gadgets v0.10.3/go.mod h1:9bgxU4rUi4NQaZCgvuLvo6BwHsCx35kNyDalztYNT3A=
|
||||||
|
go.wit.com/gui/gadgets/repostatus v0.0.0-20240110012216-abd9781d8a60 h1:7Oppvb22yhrNbYJlUJzOeTDrb3Edll4d4xfprmFe8qw=
|
||||||
|
go.wit.com/gui/gadgets/repostatus v0.0.0-20240110012216-abd9781d8a60/go.mod h1:XMqxjysTEnVeFfDbeWsA5BEDde1KfU9+Yx7YnWSqRRk=
|
||||||
|
go.wit.com/gui/gui v0.12.4 h1:99fXbCk5r/5Fg11O7Rsq6mUGltK3v8yfX2f06eaYIkU=
|
||||||
|
go.wit.com/gui/gui v0.12.4/go.mod h1:WrAJB4kIR/U0z/PzrkYYQG6QeuXDLcpgiH5vXnz5I1s=
|
||||||
|
go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93 h1:zCzaHvXJJ/rWXmDc/v79VvM6W2lxxzJGfnW2lHCv3Ho=
|
||||||
|
go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E=
|
||||||
|
go.wit.com/log v0.5.1 h1:D1Gdpo+EIOZDnBmW2SJCmqSD30ZWTGZ++NXyXeyMd2Y=
|
||||||
|
go.wit.com/log v0.5.1/go.mod h1:0oxmE+WavwUZspnVAcOuIjS3vx7qVOFXj3vmUqKlzTE=
|
||||||
|
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 h1:UEX2EzLQPzLTfy/kUFQD7OXtvKn8wk/+jpDOkbl4ff4=
|
||||||
|
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9/go.mod h1:qBpgJXThMMT15vym7/E4Ur9y8oOo2nP7t2RP52QHUNw=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
123
main.go
123
main.go
|
@ -27,7 +27,7 @@ type repo struct {
|
||||||
bLabel *gui.Node // branch label
|
bLabel *gui.Node // branch label
|
||||||
lastLabel *gui.Node // last tagged version label
|
lastLabel *gui.Node // last tagged version label
|
||||||
vLabel *gui.Node // version label
|
vLabel *gui.Node // version label
|
||||||
tagsDrop *gui.Node // list of all tags
|
// tagsDrop *gui.Node // list of all tags
|
||||||
dirtyLabel *gui.Node // git state (dirty or not?)
|
dirtyLabel *gui.Node // git state (dirty or not?)
|
||||||
|
|
||||||
masterVersion *gui.Node // the master branch version
|
masterVersion *gui.Node // the master branch version
|
||||||
|
@ -44,25 +44,44 @@ func main() {
|
||||||
myGui = gui.New().Default()
|
myGui = gui.New().Default()
|
||||||
|
|
||||||
repoworld()
|
repoworld()
|
||||||
checkrepos()
|
|
||||||
|
/*
|
||||||
|
for i, r := range allrepos {
|
||||||
|
log.Warn("scannning", i, r.path)
|
||||||
|
r.scan()
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
gui.Watchdog()
|
gui.Watchdog()
|
||||||
}
|
}
|
||||||
|
|
||||||
func addRepo(grid *gui.Node, path string) *repo {
|
func (r *repo) getPath() string {
|
||||||
|
return r.path
|
||||||
|
}
|
||||||
|
|
||||||
|
func addRepo(grid *gui.Node, path string) {
|
||||||
newRepo := new(repo)
|
newRepo := new(repo)
|
||||||
|
|
||||||
|
if repostatus.VerifyLocalGoRepo(path) {
|
||||||
|
log.Warn("newRepo actually exists", newRepo.getPath())
|
||||||
|
} else {
|
||||||
|
log.Warn("newRepo does not exist", newRepo.getPath())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
newRepo.path = path
|
newRepo.path = path
|
||||||
newRepo.pLabel = grid.NewLabel(path)
|
newRepo.pLabel = grid.NewLabel(path)
|
||||||
newRepo.bLabel = grid.NewLabel("")
|
newRepo.bLabel = grid.NewLabel("")
|
||||||
newRepo.lastLabel = grid.NewLabel("")
|
newRepo.lastLabel = grid.NewLabel("")
|
||||||
newRepo.vLabel = grid.NewLabel("")
|
newRepo.vLabel = grid.NewLabel("")
|
||||||
newRepo.tagsDrop = grid.NewDropdown("tags")
|
// newRepo.tagsDrop = grid.NewDropdown("tags")
|
||||||
|
|
||||||
newRepo.masterVersion = grid.NewLabel("")
|
newRepo.masterVersion = grid.NewLabel("")
|
||||||
newRepo.develVersion = grid.NewLabel("")
|
newRepo.develVersion = grid.NewLabel("")
|
||||||
newRepo.jcarrVersion = grid.NewLabel("")
|
newRepo.jcarrVersion = grid.NewLabel("")
|
||||||
newRepo.dirtyLabel = grid.NewLabel("")
|
newRepo.dirtyLabel = grid.NewLabel("")
|
||||||
|
|
||||||
|
/*
|
||||||
newRepo.cButton = grid.NewButton("status", func () {
|
newRepo.cButton = grid.NewButton("status", func () {
|
||||||
log.Println("repo status for", newRepo.path)
|
log.Println("repo status for", newRepo.path)
|
||||||
newRepo.scan()
|
newRepo.scan()
|
||||||
|
@ -76,16 +95,49 @@ func addRepo(grid *gui.Node, path string) *repo {
|
||||||
}
|
}
|
||||||
newRepo.status.Toggle()
|
newRepo.status.Toggle()
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
newRepo.pButton = grid.NewButton("rescan", func () {
|
newRepo.pButton = grid.NewButton("rescan", func () {
|
||||||
newRepo.scan()
|
newRepo.newScan()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
grid.NewButton("Sierpiński", func () {
|
||||||
|
if newRepo.status != nil {
|
||||||
|
log.Warn("status window already exists")
|
||||||
|
}
|
||||||
|
newRepo.status = repostatus.New(myGui, newRepo.path)
|
||||||
|
newRepo.status.Horizontal()
|
||||||
|
newRepo.status.Make()
|
||||||
|
newRepo.status.Make2()
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
grid.NewButton("Toggle()", func () {
|
||||||
|
if newRepo.status == nil {
|
||||||
|
log.Warn("status window doesn't exist")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Warn("status window exists. trying Update() here")
|
||||||
|
newRepo.status.Toggle()
|
||||||
|
})
|
||||||
|
grid.NewButton("TestDraw()", func () {
|
||||||
|
if newRepo.status == nil {
|
||||||
|
log.Warn("status window doesn't exist")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Warn("status window exists. trying TestDraw() here")
|
||||||
|
newRepo.status.TestDraw()
|
||||||
})
|
})
|
||||||
if path == "" {
|
if path == "" {
|
||||||
newRepo.cButton.Hide()
|
newRepo.cButton.Hide()
|
||||||
newRepo.pButton.Hide()
|
newRepo.pButton.Hide()
|
||||||
return newRepo
|
|
||||||
}
|
}
|
||||||
|
newRepo.status = repostatus.New(myGui, newRepo.path)
|
||||||
|
newRepo.status.Horizontal()
|
||||||
|
newRepo.status.Make()
|
||||||
|
newRepo.status.Make2()
|
||||||
|
newRepo.status.Update()
|
||||||
|
newRepo.newScan()
|
||||||
allrepos = append(allrepos, newRepo)
|
allrepos = append(allrepos, newRepo)
|
||||||
return newRepo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This creates a window
|
// This creates a window
|
||||||
|
@ -100,14 +152,15 @@ func repoworld() {
|
||||||
grid.NewLabel("")
|
grid.NewLabel("")
|
||||||
grid.NewLabel("branch")
|
grid.NewLabel("branch")
|
||||||
grid.NewLabel("last tag")
|
grid.NewLabel("last tag")
|
||||||
grid.NewLabel("Version")
|
grid.NewLabel("Current Version")
|
||||||
grid.NewLabel("tags")
|
// grid.NewLabel("tags")
|
||||||
grid.NewLabel("master")
|
grid.NewLabel("master")
|
||||||
grid.NewLabel("devel")
|
grid.NewLabel("devel")
|
||||||
grid.NewLabel("jcarr")
|
grid.NewLabel("jcarr")
|
||||||
grid.NewLabel("Status")
|
grid.NewLabel("Status")
|
||||||
grid.NewLabel("commit")
|
grid.NewLabel("commit")
|
||||||
grid.NewLabel("push to")
|
grid.NewLabel("Toggle()")
|
||||||
|
grid.NewLabel("Draw()")
|
||||||
|
|
||||||
repos := myrepolist()
|
repos := myrepolist()
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
|
@ -146,3 +199,53 @@ func myrepolist() []string {
|
||||||
lines := strings.Split(out, "\n")
|
lines := strings.Split(out, "\n")
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *repo) newScan() bool {
|
||||||
|
if r.status == nil {
|
||||||
|
log.Warn("repo.status = nil. not initialized for some reason")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// r.scan()
|
||||||
|
if repostatus.VerifyLocalGoRepo(r.getPath()) {
|
||||||
|
log.Warn("repo actually exists", r.getPath())
|
||||||
|
} else {
|
||||||
|
log.Warn("repo does not exist", r.getPath())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
mn := r.status.GetMasterName()
|
||||||
|
mv := r.status.GetMasterVersion()
|
||||||
|
r.masterVersion.Set(mn + " " + mv)
|
||||||
|
|
||||||
|
dn := r.status.GetDevelName()
|
||||||
|
dv := r.status.GetDevelVersion()
|
||||||
|
r.develVersion.Set(dn + " " + dv)
|
||||||
|
|
||||||
|
un := r.status.GetUserName()
|
||||||
|
uv := r.status.GetUserVersion()
|
||||||
|
r.jcarrVersion.Set(un + " " + uv)
|
||||||
|
|
||||||
|
cbname := r.status.GetCurrentBranchName()
|
||||||
|
cbversion := r.status.GetCurrentBranchVersion()
|
||||||
|
ltversion := r.status.GetLastTagVersion()
|
||||||
|
r.lastLabel.Set(cbname + " " + cbversion)
|
||||||
|
r.vLabel.Set(cbname + " " + ltversion)
|
||||||
|
|
||||||
|
if r.status.CheckDirty() {
|
||||||
|
log.Warn("CheckDirty() true")
|
||||||
|
r.dirtyLabel.Set("dirty")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
log.Warn("CheckDirty() no")
|
||||||
|
r.dirtyLabel.Set("not dirty")
|
||||||
|
|
||||||
|
if r.status.CheckBranches() {
|
||||||
|
log.Warn("Branches are Perfect")
|
||||||
|
r.dirtyLabel.SetText("PEFECT")
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
log.Warn("Branches are not Perfect")
|
||||||
|
r.dirtyLabel.SetText("merge")
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
96
unix.go
96
unix.go
|
@ -1,96 +0,0 @@
|
||||||
// This is a simple example
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
|
||||||
|
|
||||||
// "go.wit.com/gui/gui"
|
|
||||||
// "go.wit.com/gui/gadgets"
|
|
||||||
// "go.wit.com/apps/control-panel-dns/smartwindow"
|
|
||||||
)
|
|
||||||
|
|
||||||
func fullpath(repo string) string {
|
|
||||||
return "/home/jcarr/go/src/" + repo
|
|
||||||
}
|
|
||||||
|
|
||||||
func run(path string, thing string, cmdline string) string {
|
|
||||||
parts := strings.Split(cmdline, " ")
|
|
||||||
// Create the command
|
|
||||||
cmd := exec.Command(thing, parts...)
|
|
||||||
|
|
||||||
// Set the working directory
|
|
||||||
cmd.Dir = fullpath(path)
|
|
||||||
|
|
||||||
// Execute the command
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err, "cmd error'd out", parts)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp := string(output)
|
|
||||||
|
|
||||||
tmp = strings.TrimSpace(tmp)
|
|
||||||
|
|
||||||
// Print the output
|
|
||||||
log.Info("run()", path, thing, cmdline, "=", tmp)
|
|
||||||
return tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
func listFiles(directory string) []string {
|
|
||||||
var files []string
|
|
||||||
fileInfo, err := os.ReadDir(directory)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file := range fileInfo {
|
|
||||||
if !file.IsDir() {
|
|
||||||
files = append(files, file.Name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return files
|
|
||||||
}
|
|
||||||
|
|
||||||
func runCmd(path string, cmdline string) (bool, string) {
|
|
||||||
parts := strings.Split(cmdline, " ")
|
|
||||||
if len(parts) == 0 {
|
|
||||||
log.Warn("command line was empty")
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
if parts[0] == "" {
|
|
||||||
log.Warn("command line was empty")
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
thing := parts[0]
|
|
||||||
parts = parts[1:]
|
|
||||||
|
|
||||||
log.Warn("path =", path, "thing =", thing, "cmdline =", parts)
|
|
||||||
return false, ""
|
|
||||||
// Create the command
|
|
||||||
cmd := exec.Command(thing, parts...)
|
|
||||||
|
|
||||||
// Set the working directory
|
|
||||||
cmd.Dir = fullpath(path)
|
|
||||||
|
|
||||||
// Execute the command
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
log.Warn("output was", output)
|
|
||||||
log.Warn("cmd exited with error", err)
|
|
||||||
return false, string(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp := string(output)
|
|
||||||
tmp = strings.TrimSpace(tmp)
|
|
||||||
|
|
||||||
// Print the output
|
|
||||||
return true, tmp
|
|
||||||
}
|
|
Loading…
Reference in New Issue