summaryrefslogtreecommitdiff
path: root/init.go
blob: 68ee54faa813fe2b19195b6fc0949252343edcca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package argvpb

import (
	"fmt"
	"time"

	"github.com/google/uuid"
	"go.wit.com/lib/cobol"
	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)

func Init(dest any, APPNAME string, anyString string, VERSION string) {
	me = new(AutoType)
	me.pb = new(Argv)
	PB = me.pb

	// needed by bash for autocomplete, help & debugging
	Stdout = NewStringWriter(&PB.Stdout) // bash uses this to match strings
	Stderr = NewStringWriter(&PB.Stderr) // bash dumps this as "help" about application options
	Stddbg = NewStringWriter(&PB.Stderr) // argv writes it's internal debugging output here

	app := new(App)
	app.APPNAME = APPNAME
	app.VERSION = VERSION
	//
	// this logic isn't great, but it's what it is right now
	//
	// the reason this logic is messy is because cobol is supposed to "guess"
	// that is the point of the cobol package and I've been using this code here
	// to test the guesses because it's an easy place to test that code
	//
	if BUILDTIME, err := cobol.GetTime(anyString); BUILDTIME != nil {
		// everyhting is working. BUILDTIME is *time.Time
		app.BUILDTIME = cobol.Time(BUILDTIME)
	} else if err == nil {
		newtime := BUILDTIME.Add(-36 * time.Hour)
		app.BUILDTIME = cobol.Time(BUILDTIME)
		fmt.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, newtime, app.BUILDTIME)
	} else {
		app.BUILDTIME = anyString
		fmt.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, BUILDTIME, app.BUILDTIME)
	}
	me.pb.AppInfo = app

	// shouldn't be needed but is because this code doesn't work right yet
	me.pb.Uuid = uuid.New().String()

	// set the start time of the binary
	now := time.Now()
	me.pb.Ctime = timestamppb.New(now)

	// makes sure the application has the
	// needed functions defined, otherwise dies
	verifyApplication(dest)

	// do autocomplete
	Autocomplete()
}