diff --git a/cmd/main.go b/cmd/main.go index b751526..1fa48db 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -235,8 +235,7 @@ func initFunc(ctx *cli.Context) error { logger.Level = logrus.DebugLevel } - logger.Infoln("Initializing doggofetcher...") - return pkg.Init() + return pkg.Init(logger) } func uninstall(ctx *cli.Context) error { diff --git a/pkg/utils.go b/pkg/utils.go index 0d67c79..d1cc34e 100644 --- a/pkg/utils.go +++ b/pkg/utils.go @@ -6,6 +6,8 @@ import ( "os" "path/filepath" "strings" + + "github.com/sirupsen/logrus" ) func UpdateRelease(releaseFolder string) error { @@ -67,31 +69,22 @@ func CopyFolder(src, dst string, init bool) error { return nil } -func Init() error { +func Init(logger *logrus.Logger) error { dgfFolder := strings.Replace(DGF_FOLDER, "~", os.Getenv("HOME"), 1) + logger.WithField("folder", dgfFolder).Infoln("Initializing doggofetcher folder") + if err := os.MkdirAll(dgfFolder, 0755); err != nil { return err } - - f, err := os.OpenFile(getShellConfigFile(), os.O_WRONLY|os.O_APPEND, 0755) + f, err := os.Create(filepath.Join(dgfFolder, "hashes.txt")) if err != nil { return err } - defer f.Close() + f.Close() - msg := fmt.Sprintln("\n\n# doggofetcher section") - msg += fmt.Sprintf("export PATH=%s:$PATH\n", filepath.Join(dgfFolder, "go", "bin")) - if _, err := f.WriteString(msg); err != nil { - return err - } + logger.Infoln("Add doggofetcher to your shell configuration file with the following command:") + fmt.Fprintln(os.Stdout, "\n# doggofetcher section") + fmt.Fprintf(os.Stdout, "export PATH=%s:$PATH\n", filepath.Join(dgfFolder, "go", "bin")) return nil } - -func getShellConfigFile() string { - if strings.Contains(os.Getenv("SHELL"), "zsh") { - return fmt.Sprintf("%s/.zshrc", os.Getenv("HOME")) - } - - return fmt.Sprintf("%s/.bashrc", os.Getenv("HOME")) -}