Skip to content

Commit

Permalink
fix creating files
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusLindroth committed May 7, 2022
1 parent 9958d2f commit 0a4e92a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a4e92a

Please sign in to comment.