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.Level = logrus.DebugLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infoln("Initializing doggofetcher...")
|
return pkg.Init(logger)
|
||||||
return pkg.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func uninstall(ctx *cli.Context) error {
|
func uninstall(ctx *cli.Context) error {
|
||||||
|
|
27
pkg/utils.go
27
pkg/utils.go
|
@ -6,6 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateRelease(releaseFolder string) error {
|
func UpdateRelease(releaseFolder string) error {
|
||||||
|
@ -67,31 +69,22 @@ func CopyFolder(src, dst string, init bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() error {
|
func Init(logger *logrus.Logger) error {
|
||||||
dgfFolder := strings.Replace(DGF_FOLDER, "~", os.Getenv("HOME"), 1)
|
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 {
|
if err := os.MkdirAll(dgfFolder, 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
f, err := os.Create(filepath.Join(dgfFolder, "hashes.txt"))
|
||||||
f, err := os.OpenFile(getShellConfigFile(), os.O_WRONLY|os.O_APPEND, 0755)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
f.Close()
|
||||||
|
|
||||||
msg := fmt.Sprintln("\n\n# doggofetcher section")
|
logger.Infoln("Add doggofetcher to your shell configuration file with the following command:")
|
||||||
msg += fmt.Sprintf("export PATH=%s:$PATH\n", filepath.Join(dgfFolder, "go", "bin"))
|
fmt.Fprintln(os.Stdout, "\n# doggofetcher section")
|
||||||
if _, err := f.WriteString(msg); err != nil {
|
fmt.Fprintf(os.Stdout, "export PATH=%s:$PATH\n", filepath.Join(dgfFolder, "go", "bin"))
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
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