// 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/gui/prep" "go.wit.com/lib/protobuf/filepb" "go.wit.com/log" ) // sent via -ldflags var VERSION string var BUILDTIME string // used for shell auto completion var ARGNAME string = "wit" // todo: get this from $0 ? //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.sh = prep.Bash(&argv) // add support for bash autocomplete with go-arg me.homedir, _ = os.UserHomeDir() // store shortcut here todo: add better logic if me.sh.Cmd == "" { // user didn't enter a sub command // doDefaultBehavior() me.sh.GoodExit("do what?") } setTitle("wit %s" + me.sh.Cmd) // Standard subcommand handling starts here var s string var err error if argv.Upgrade != nil { doUpgrade() me.sh.GoodExit("") } if argv.Linux != nil { if argv.Linux.Rdate != nil { s, err = doRdate() } else { setTerminalTitle("pinging google", "ping", []string{"google.com"}) } } if argv.Build != nil { s, err = doBuild() } if argv.Git != nil { initMachine() s, err = doGit() } if argv.PB != nil { s, err = doIdentifyPB("unknown.pb") } if argv.Clone != nil { doClone() me.sh.GoodExit("") } if argv.WITCOM { doWITCOM() me.sh.GoodExit("") } if argv.Clone != nil { doClone() me.sh.GoodExit("") } if argv.WITCOM { doWITCOM() me.sh.GoodExit("") } if argv.Upgrade != nil { doUpgrade() } if argv.Publish != nil { if err := doPublish(); err != nil { me.sh.BadExit("doPublish failed", err) } me.sh.GoodExit("") } if argv.Zoo != nil { if areSuperuser() { exitOnErrorRealtime([]string{"journalctl", "-n", "100", "-f", "_SYSTEMD_UNIT=zood.service"}) } me.sh.GoodExit("do something here") } if err != nil { me.sh.BadExit(s, err) } me.sh.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 "" } // print the protobuf in human form func doIdentifyPB(filename string) (string, error) { data, err := os.ReadFile(filename) if err != nil { // log.Info("open config file :", err) return "os.ReadFile()", err } var pb *filepb.Identify pb = new(filepb.Identify) if err := pb.Unmarshal(data); err != nil { return "Unmarshal(data)", err } log.Info("Identify protobuf file uuid =", pb.Uuid, "version =", pb.Version) return "file identify worked!", nil }