From b09b86009ecb17c171aab400af73a568d084f49e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 23 Sep 2025 12:14:26 -0500 Subject: [PATCH] some fun stuff --- Makefile | 8 +++++--- argv.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ doList.go | 19 ++++++++++--------- main.go | 6 ++---- structs.go | 1 + 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 7c193f0..b533cd5 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ .PHONY: build 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 - ./forged list +all: build + ./forged --version + # FORGE_VERBOSE=true ./forged list build: goimports GO111MODULE=off go build \ diff --git a/argv.go b/argv.go index ae0366e..7baf9c8 100644 --- a/argv.go +++ b/argv.go @@ -8,6 +8,12 @@ package main import ( "fmt" "os" + "strconv" + "strings" + "time" + + "go.wit.com/lib/gui/prep" + "go.wit.com/lib/gui/shell" ) var argv args @@ -29,17 +35,51 @@ type args struct { type EmptyCmd struct { } +func (args) Appname() string { + return ARGNAME +} + 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 } -func (a args) DoAutoComplete(argv []string) { - // argv.doBashHelp() - switch argv[0] { - case "merge": - fmt.Println("--force") +func (a args) DoAutoComplete(pb *prep.Auto) { + switch pb.Cmd { + case "list": + pb.Autocomplete2("--missing") + case "clean": + pb.Autocomplete2("") default: - fmt.Println("list merge repos") + pb.Autocomplete2("list clean") } os.Exit(0) } diff --git a/doList.go b/doList.go index a7b2a17..beb6187 100644 --- a/doList.go +++ b/doList.go @@ -6,20 +6,21 @@ import ( ) func doList() error { - log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len()) for pset := range me.forge.Patchsets.IterAll() { pset.PrintTable() } - /* - // show all the patchsets with Names - for pset := range me.forge.Patchsets.IterAll() { - log.Info("Info", pset.Name, pset.Uuid) - for i, patch := range pset.Patches.Patches { - log.Info("\t", i, patch.CommitHash, patch.Namespace) - } + return nil +} + +func doClean() error { + log.Infof("clean Patchsets.Len()=%d\n", me.forge.Patchsets.Len()) + // show all the patchsets with Names + for pset := range me.forge.Patchsets.IterAll() { + for patch := range pset.Patches.IterAll() { + log.Info("\t", patch.CommitHash, patch.PatchId, patch.Namespace) } - */ + } return nil } diff --git a/main.go b/main.go index eb37459..760914a 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "net/http" "time" - "go.wit.com/dev/alexflint/arg" "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/forgepb" @@ -27,9 +26,8 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this func main() { 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.pp = arg.MustParse(&argv) + me.myGui = prep.Gui() // prepares the GUI package for go-args + me.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv) me.forge = forgepb.InitByAppname(ARGNAME) diff --git a/structs.go b/structs.go index d21e9f8..22f5b01 100644 --- a/structs.go +++ b/structs.go @@ -16,5 +16,6 @@ type mainType struct { pp *arg.Parser // for parsing the command line args. Yay to alexf lint! forge *forgepb.Forge // for holding the forge protobuf files myGui *prep.GuiPrep // the gui toolkit handle + auto *prep.Auto // more experiments for bash handling configs *forgepb.ForgeConfigs // for holding the forge protobuf files }