summaryrefslogtreecommitdiff
path: root/main.go
blob: e972da0df6705de5162b3ff31b8741aa1940f5ec (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"embed"
	"os"
	"unicode"

	"go.wit.com/lib/protobuf/argvpb"
	"go.wit.com/log"
)

//go:embed resources/*
var resources embed.FS

func main() {
	me = new(mainType)
	// autocomplete must be processed before there is anything sent to STDOUT or STDERR
	me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args
	me.homedir, _ = os.UserHomeDir()     // store shortcut here todo: add better logic

	if me.argv.GetCmd() == "" {
		// user didn't enter a sub command
		// doDefaultBehavior()
		me.argv.GoodExit("do what?")
	}

	pwd, _ := os.Getwd()
	setTitle(log.Sprintf("wit %s %s", me.argv.GetCmd(), pwd))

	// Standard subcommand handling starts here
	var s string
	var err error

	// process the argv subcommand (subCommand.go)
	s, err = subCommand()

	// argv provides timing and other features on exit
	if err != nil {
		// bad exit back to the shell via argv
		me.argv.BadExit(s, err)
	}
	// a good exit back to the shell via argv
	me.argv.GoodExit(s)
}

// this is dumb. sync this with go-deb
func trimNonNumericFromStart(s string) string {
	for i, r := range s {
		if unicode.IsDigit(r) {
			return s[i:]
		}
	}
	return ""
}