get git version

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-09 02:00:51 -06:00
parent a0be4a93d1
commit 96379b6279
2 changed files with 71 additions and 4 deletions

View File

@ -1,6 +1,6 @@
all:
go build -v -x
./control-panel-vpn
./myrepos
redomod:
rm -f go.*

73
main.go
View File

@ -2,7 +2,11 @@
package main
import (
"log"
"strings"
"os/exec"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
"go.wit.com/apps/control-panel-dns/smartwindow"
@ -19,11 +23,54 @@ func main() {
gui.Watchdog()
}
func addRepo(grid *gui.Node, path string) {
grid.NewLabel(path)
ver := grid.NewLabel("VERSION")
b, out := run(path, "git", "describe --tags")
if b {
ver.SetText(out)
}
// cmd := "dig +noall +answer www.wit.com A"
// out = shell.Run(cmd)
grid.NewLabel("jcarr")
grid.NewLabel("dirty")
grid.NewButton("commit", func () {
log.Println("world")
hellosmart()
})
grid.NewButton("push", func () {
log.Println("world")
hellosmart()
})
}
// This creates a window
func helloworld() {
win := gadgets.NewBasicWindow(myGui, "helloworld golang wit/gui window")
win.Box().NewButton("hello", func () {
box := win.Box().NewBox("bw vbox", false)
group := box.NewGroup("test")
grid := group.NewGrid("test", 6, 1)
grid.NewLabel("Repo")
grid.NewLabel("Version")
grid.NewLabel("Current branch")
grid.NewLabel("is dirty?")
grid.NewLabel("commit")
grid.NewLabel("push to")
addRepo(grid, "go.wit.com/log")
addRepo(grid, "go.wit.com/arg")
addRepo(grid, "go.wit.com/spew")
addRepo(grid, "go.wit.com/shell")
addRepo(grid, "")
addRepo(grid, "go.wit.com/gui/gadgets")
addRepo(grid, "go.wit.com/gui/gadgets")
box.NewButton("hello", func () {
log.Println("world")
hellosmart()
})
@ -39,7 +86,7 @@ func hellosmart() {
win.SetDraw(smartDraw)
win.Make()
win.Box().NewButton("hello", func () {
win.Box().NewButton("test smartwindow", func () {
log.Println("smart")
})
}
@ -49,3 +96,23 @@ func smartDraw(sw *smartwindow.SmartWindow) {
log.Println("smart")
})
}
func run(path string, thing string, cmdline string) (bool, string) {
parts := strings.Split(cmdline, " ")
// Create the command
cmd := exec.Command(thing, parts...)
// Set the working directory
cmd.Dir = "/home/jcarr/go/src/" + path
// Execute the command
output, err := cmd.CombinedOutput()
if err != nil {
log.Error(err, "cmd error'd out", parts)
return false, ""
}
// Print the output
log.Info(string(output))
return true, string(output)
}