package main /* this parses the command line arguements this enables command line options from other packages like 'gui' and 'log' */ import ( "fmt" "os" "strconv" "strings" "time" "go.wit.com/lib/gui/prep" "go.wit.com/lib/gui/shell" ) var argv args type args struct { Repos *ReposCmd `arg:"subcommand:repos" help:"the forged repos"` Patch *PatchCmd `arg:"subcommand:patches" help:"the forged patches"` Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"` Missing *EmptyCmd `arg:"subcommand:missing" help:"list missing repos"` Port int `arg:"--port" default:"2520" help:"port to run on"` Hostname string `arg:"--hostname" help:"hostname to use"` Daemon bool `arg:"--daemon" help:"run as a daemon"` Force bool `arg:"--force" help:"try to strong arm things"` Verbose bool `arg:"--verbose" help:"show more output"` } type EmptyCmd struct { } type PatchCmd struct { List *EmptyCmd `arg:"subcommand:list" help:"list the patches"` Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the patches"` Init *EmptyCmd `arg:"subcommand:init" help:"init"` } type ReposCmd struct { List *EmptyCmd `arg:"subcommand:list" help:"list the repos"` Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"` Scan *EmptyCmd `arg:"subcommand:scan" help:"scan the forged repo dir"` Fix *EmptyCmd `arg:"subcommand:fix" help:"try to fix the repo PB"` Devel *EmptyCmd `arg:"subcommand:devel" help:"list repos with devel branches"` Reload *EmptyCmd `arg:"subcommand:reload" help:"gitpb.Reload() each repo"` // Reload *EmptyCmd `arg:"subcommand:reload" help:"do Reload() on each git repo"` // Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the repos"` // Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"` } func (args) Appname() string { return ARGNAME } func (args) Buildtime() (string, string) { return BUILDTIME, VERSION } 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 } /* handles shell autocomplete */ func (a args) DoAutoComplete(pb *prep.Auto) { if pb.Cmd == "" { pb.Autocomplete3([]string{"--bash", "repos", "gui", "patches", "--daemon", "missing"}) } else { pb.SubCommand(pb.Argv...) } os.Exit(0) }