Skip to content

Commit

Permalink
feat: osとarchをinstall scriptに渡すように
Browse files Browse the repository at this point in the history
  • Loading branch information
anoriqq committed May 6, 2022
1 parent 4302c75 commit 49128d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
17 changes: 13 additions & 4 deletions internal/cmd/install.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
}
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"os"

"github.com/anoriqq/qpm/internal/cmd"
Expand All @@ -10,7 +9,6 @@ import (
func main() {
err := cmd.Execute()
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}
}

0 comments on commit 49128d9

Please sign in to comment.