Compare commits

...

4 Commits

Author SHA1 Message Date
Jeff Carr 460338c4eb add /sets/ 2025-09-23 14:50:23 -05:00
Jeff Carr cd545c7c9f add doClean() 2025-09-23 14:50:22 -05:00
Jeff Carr b09b86009e some fun stuff 2025-09-23 14:50:21 -05:00
Jeff Carr 1f22b771c3 something good about this 2025-09-23 14:50:19 -05:00
6 changed files with 131 additions and 17 deletions

View File

@ -1,10 +1,12 @@
.PHONY: build .PHONY: build
VERSION = $(shell git describe --tags) VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M) # BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
BUILDTIME = $(shell date +%s)
all: build-verbose all: build
./forged list FORGE_VERBOSE=true ./forged clean
# FORGE_VERBOSE=true ./forged list
build: goimports build: goimports
GO111MODULE=off go build \ GO111MODULE=off go build \

53
argv.go
View File

@ -8,6 +8,12 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strconv"
"strings"
"time"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/gui/shell"
) )
var argv args var argv args
@ -15,6 +21,7 @@ var argv args
type args struct { type args struct {
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"` Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"` List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the repos"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"` Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"`
Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"` Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"`
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"` Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
@ -29,17 +36,51 @@ type args struct {
type EmptyCmd struct { type EmptyCmd struct {
} }
func (args) Appname() string {
return ARGNAME
}
func (args) Version() string { func (args) Version() string {
parts := strings.Split(BUILDTIME, ".")
if len(parts) == 1 {
// The input epoch seconds
// epochSeconds := int64(1758646486)
num, err := strconv.Atoi(BUILDTIME)
epochSeconds := int64(num)
if err == nil {
// 1. Convert the epoch seconds to a time.Time object.
// time.Unix() creates the time in the UTC timezone by default.
t := time.Unix(epochSeconds, 0)
// 2. Convert the UTC time to the computer's local timezone.
localTime := t.Local()
// 3. Print the result. The default format is clear and includes the timezone.
// fmt.Println("Default format:", localTime)
// For a more human-friendly format, use the Format() method.
// Go uses a special reference time for formatting: Mon Jan 2 15:04:05 2006 MST
// You lay out your desired format using these specific numbers.
// formattedString := localTime.Format("Monday, January 2, 2006 at 3:04:05 PM (MST)")
// fmt.Println(" Custom format:", formattedString)
// now := time.Now()
// dur := time.Since(localTime)
BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), shell.FormatDuration(time.Since(localTime)))
}
}
return ARGNAME + " " + VERSION + " Built on " + BUILDTIME return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
} }
func (a args) DoAutoComplete(argv []string) { func (a args) DoAutoComplete(pb *prep.Auto) {
// argv.doBashHelp() switch pb.Cmd {
switch argv[0] { case "list":
case "merge": pb.Autocomplete2("--missing")
fmt.Println("--force") case "clean":
pb.Autocomplete2("")
default: default:
fmt.Println("list merge repos") pb.Autocomplete2("list clean")
} }
os.Exit(0) os.Exit(0)
} }

View File

@ -6,15 +6,27 @@ import (
) )
func doList() error { func doList() error {
log.Info("do list here") log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
for pset := range me.forge.Patchsets.IterAll() {
pset.PrintTable()
}
return nil
}
func doClean() error {
log.Infof("clean Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
// show all the patchsets with Names // show all the patchsets with Names
for pset := range me.forge.Patchsets.IterAll() { for pset := range me.forge.Patchsets.IterAll() {
log.Info("Info", pset.Name, pset.Uuid) for patch := range pset.Patches.IterAll() {
for i, patch := range pset.Patches.Patches { if patch.PatchId == "" {
log.Info("\t", i, patch.CommitHash, patch.Namespace) log.Info("Delete", patch.CommitHash, patch.PatchId, patch.Namespace)
pset.Patches.Delete(patch)
} else {
log.Info("\t", patch.CommitHash, patch.PatchId, patch.Namespace)
} }
} }
}
me.forge.SavePatchsets()
return nil return nil
} }

47
http.go
View File

@ -63,6 +63,53 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if strings.HasPrefix(route, "/set/") {
pb := new(forgepb.Set)
if err := pb.Unmarshal(reqPB.ClientData); err != nil {
reqPB.Logf("Patches Unmarshal() len(data)=%d err=%v", len(reqPB.ClientData), err)
logReqPB(reqPB)
return
}
reqPB.Logf("Patches Unmarshal() len=%d", pb.Patches.Len())
result := new(forgepb.Set)
switch route {
case "/set/new":
me.forge.Patchsets.Append(pb)
reqPB.Logf("addNewPatches() pb.Patches.Len()=%d Patchsets.Len()=%d", pb.Patches.Len(), me.forge.Patchsets.Len())
me.forge.SavePatchsets()
result.Uuid = pb.Uuid
default:
}
if err := result.SendReply(w, reqPB); err != nil {
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
}
// todo: logReq(reqPB)
logReqPB(reqPB)
return
}
if strings.HasPrefix(route, "/sets/") {
pb := forgepb.NewSets()
if err := pb.Unmarshal(reqPB.ClientData); err != nil {
reqPB.Logf("Patches Unmarshal() len(data)=%d err=%v", len(reqPB.ClientData), err)
logReqPB(reqPB)
return
}
reqPB.Logf("Patches Unmarshal() len=%d", pb.Len())
switch route {
case "/sets/get":
if err := me.forge.Patchsets.SendReply(w, reqPB); err != nil {
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
} else {
reqPB.Logf("SendReply() worked")
}
default:
}
// todo: logReq(reqPB)
logReqPB(reqPB)
return
}
if strings.HasPrefix(route, "/patches/") { if strings.HasPrefix(route, "/patches/") {
pb := forgepb.NewPatches() pb := forgepb.NewPatches()
if err := pb.Unmarshal(reqPB.ClientData); err == nil { if err := pb.Unmarshal(reqPB.ClientData); err == nil {

17
main.go
View File

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"time" "time"
"go.wit.com/dev/alexflint/arg" "go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/prep" "go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log" "go.wit.com/log"
@ -26,21 +26,32 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this
func main() { func main() {
me = new(mainType) me = new(mainType)
prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be: prep.Bash(argv)
me.myGui = prep.Gui() // prepares the GUI package for go-args me.myGui = prep.Gui() // prepares the GUI package for go-args
me.pp = arg.MustParse(&argv) me.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv)
me.forge = forgepb.InitByAppname(ARGNAME) me.forge = forgepb.InitByAppname(ARGNAME)
if err := me.forge.InitPatchsets(); err != nil { if err := me.forge.InitPatchsets(); err != nil {
log.Info("patches failed to open", err) log.Info("patches failed to open", err)
badExit(err)
} }
if argv.List != nil { if argv.List != nil {
log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len())
fhelp.DumpENV("finit:")
me.forge.Config.DumpENV()
doList() doList()
okExit("") okExit("")
} }
if argv.Clean != nil {
log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len())
fhelp.DumpENV("finit:")
me.forge.Config.DumpENV()
doClean()
okExit("")
}
if argv.Merge != nil { if argv.Merge != nil {
if err := doMerge(); err != nil { if err := doMerge(); err != nil {
badExit(err) badExit(err)

View File

@ -16,5 +16,6 @@ type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint! pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files forge *forgepb.Forge // for holding the forge protobuf files
myGui *prep.GuiPrep // the gui toolkit handle myGui *prep.GuiPrep // the gui toolkit handle
auto *prep.Auto // more experiments for bash handling
configs *forgepb.ForgeConfigs // for holding the forge protobuf files configs *forgepb.ForgeConfigs // for holding the forge protobuf files
} }