diff --git a/cmd/root.go b/cmd/root.go index bf949ed..ced6191 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,6 +3,7 @@ package cmd import ( "os" + "github.com/arashnrim/tp/utils" "github.com/spf13/cobra" ) @@ -25,3 +26,7 @@ func Execute() { os.Exit(1) } } + +func init() { + utils.ValidateConfigFolder() +} diff --git a/utils/add.go b/utils/add.go new file mode 100644 index 0000000..83d3dff --- /dev/null +++ b/utils/add.go @@ -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 +}