Skip to content

Commit

Permalink
Add check for config folder
Browse files Browse the repository at this point in the history
  • Loading branch information
arashnrim committed Feb 11, 2022
1 parent 7de54fb commit 808d46d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"os"

"github.com/arashnrim/tp/utils"
"github.com/spf13/cobra"
)

Expand All @@ -25,3 +26,7 @@ func Execute() {
os.Exit(1)
}
}

func init() {
utils.ValidateConfigFolder()
}
16 changes: 16 additions & 0 deletions utils/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package utils

import (
"os"
"path/filepath"
)

func ValidateConfigFolder() error {
folderPath := filepath.Join(os.Getenv("HOME"), ".tp")
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
if err := os.Mkdir(folderPath, 0777); err != nil {
return err
}
}
return nil
}

0 comments on commit 808d46d

Please sign in to comment.