refactor: init command
This commit is contained in:
parent
fbc6db312f
commit
1ed6c6259e
|
@ -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 {
|
||||
|
|
27
pkg/utils.go
27
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"))
|
||||
}
|
||||
|
|
Reference in New Issue