diff --git a/main.go b/main.go index 1bd5321..10fa093 100644 --- a/main.go +++ b/main.go @@ -6,12 +6,14 @@ import ( "github.com/RasmusLindroth/tut/auth" "github.com/RasmusLindroth/tut/config" "github.com/RasmusLindroth/tut/ui" + "github.com/RasmusLindroth/tut/util" "github.com/rivo/tview" ) -const version = "1.0.1" +const version = "1.0.2" func main() { + util.MakeDirs() newUser, selectedUser := ui.CliView(version) accs := auth.StartAuth(newUser) diff --git a/util/util.go b/util/util.go index 8ea4beb..027b58c 100644 --- a/util/util.go +++ b/util/util.go @@ -75,10 +75,25 @@ func CmdToString(cmd string) (string, error) { return strings.TrimSpace(string(s)), err } +func MakeDirs() { + cd, err := os.UserConfigDir() + if err != nil { + log.Printf("couldn't find $HOME. Error: %v\n", err) + os.Exit(1) + } + dir := cd + "/tut" + err = os.Mkdir(dir, 0755) + if err != nil && !os.IsExist(err) { + log.Printf("couldn't create dirs. Error: %v\n", err) + os.Exit(1) + } +} + func CheckConfig(filename string) (path string, exists bool, err error) { cd, err := os.UserConfigDir() if err != nil { - log.Fatalf("couldn't find $HOME. Err %v", err) + log.Printf("couldn't find $HOME. Error: %v\n", err) + os.Exit(1) } dir := cd + "/tut/" path = dir + filename