From 49128d9ab072b6676246b02c5fbf97fa25aadfc6 Mon Sep 17 00:00:00 2001 From: anoriqq Date: Fri, 6 May 2022 19:46:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20os=E3=81=A8arch=E3=82=92install=20scrip?= =?UTF-8?q?t=E3=81=AB=E6=B8=A1=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/cmd/install.go | 17 +++++++++++++---- internal/config/config.go | 2 +- main.go | 2 -- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/cmd/install.go b/internal/cmd/install.go index 9d47ec2..defaa1c 100644 --- a/internal/cmd/install.go +++ b/internal/cmd/install.go @@ -1,11 +1,13 @@ package cmd import ( + "bufio" "errors" "fmt" "os" "os/exec" "path/filepath" + "runtime" "github.com/AlecAivazis/survey/v2" "github.com/anoriqq/qpm/internal/config" @@ -76,7 +78,7 @@ func getPkgName(args []string) (string, error) { } func getInstallScriptPaht(scriptDir, pkgName string) (string, error) { - installScriptPath, err := filepath.Abs(fmt.Sprintf("%s/%s/install.sh", scriptDir, pkgName)) + installScriptPath, err := filepath.Abs(fmt.Sprintf("%s/%s/latest.sh", scriptDir, pkgName)) if err != nil { return "", err } @@ -90,12 +92,19 @@ func execInstallScript(installScriptPath string) error { return fmt.Errorf("install script not found: %s", installScriptPath) } - o, err := exec.Command("/bin/sh", installScriptPath).Output() + c := exec.Command("/bin/sh", installScriptPath, "install", runtime.GOOS, runtime.GOARCH) + + stdout, err := c.StdoutPipe() if err != nil { return err } - fmt.Println(string(o)) + c.Start() + + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + fmt.Println(scanner.Text()) + } - return nil + return c.Wait() } diff --git a/internal/config/config.go b/internal/config/config.go index 4ad7992..2919d46 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -87,7 +87,7 @@ func HasScriptDir() bool { func SetScriptDir(scriptDir string) error { viper.Set("ScriptDir", scriptDir) - err := viper.WriteConfig() + err := viper.WriteConfig() if err != nil { return err } diff --git a/main.go b/main.go index 32699ed..2192e2c 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "github.com/anoriqq/qpm/internal/cmd" @@ -10,7 +9,6 @@ import ( func main() { err := cmd.Execute() if err != nil { - fmt.Printf("%+v\n", err) os.Exit(1) } }