some fun stuff

This commit is contained in:
Jeff Carr 2025-09-23 12:14:26 -05:00
parent 1f22b771c3
commit b09b86009e
5 changed files with 64 additions and 22 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 ./forged --version
# FORGE_VERBOSE=true ./forged list
build: goimports build: goimports
GO111MODULE=off go build \ GO111MODULE=off go build \

52
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
@ -29,17 +35,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,20 +6,21 @@ import (
) )
func doList() error { func doList() error {
log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len()) log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
for pset := range me.forge.Patchsets.IterAll() { for pset := range me.forge.Patchsets.IterAll() {
pset.PrintTable() pset.PrintTable()
} }
/* return nil
// show all the patchsets with Names }
for pset := range me.forge.Patchsets.IterAll() {
log.Info("Info", pset.Name, pset.Uuid) func doClean() error {
for i, patch := range pset.Patches.Patches { log.Infof("clean Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
log.Info("\t", i, patch.CommitHash, patch.Namespace) // 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 return nil
} }

View File

@ -6,7 +6,6 @@ import (
"net/http" "net/http"
"time" "time"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/fhelp" "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"
@ -27,9 +26,8 @@ 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.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv)
me.pp = arg.MustParse(&argv)
me.forge = forgepb.InitByAppname(ARGNAME) me.forge = forgepb.InitByAppname(ARGNAME)

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
} }