launcher/main.go

67 lines
1.2 KiB
Go
Raw Permalink Normal View History

2023-08-19 09:30:59 +02:00
package main
import (
// Standard
"bufio"
"flag"
"fmt"
"os"
"runtime"
)
var (
mainCommandset CommandSet
flagConfigDir string
)
func main() {
var defaultConfigDir string
switch runtime.GOOS {
case "linux", "darwin":
defaultConfigDir = "Default is $HOME/.config/launcher/."
case "windows":
defaultConfigDir = "Default is %USERPROFILE\\/launcher\\."
}
flag.StringVar(
&flagConfigDir,
"config",
"",
"Specify the directory containing configuration.\n"+
defaultConfigDir,
)
flag.Parse()
// Finding the files to parse commands from
files, err := getCommandsetFiles()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Actually reading and parsing the YAML files into the
// CommandSet structs
errors := false
for _, fName := range files {
cset, err := CreateCommandSet(fName)
if err != nil {
fmt.Printf("\x1b[31m%s:\x1b[0m\n%s\n\n", fName, err)
errors = true
} else {
mainCommandset.Commands = append(
mainCommandset.Commands,
cset,
)
}
}
if errors {
fmt.Printf("\x1b[33mPress enter to continue\x1b[0m\n")
bufio.NewReader(os.Stdin).ReadBytes('\n')
os.Exit(1)
}
// Screen needs to be initialized
InitUI()
LoopUI(&mainCommandset)
}