From ce936547e996fc0d1ac8509eef605ef177ba413f Mon Sep 17 00:00:00 2001 From: anoriqq Date: Fri, 6 May 2022 17:57:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20script=20dir=E3=82=92=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=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 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/cmd/install.go b/internal/cmd/install.go index ac06924..9d47ec2 100644 --- a/internal/cmd/install.go +++ b/internal/cmd/install.go @@ -3,9 +3,11 @@ package cmd import ( "errors" "fmt" + "os" "os/exec" "path/filepath" + "github.com/AlecAivazis/survey/v2" "github.com/anoriqq/qpm/internal/config" "github.com/spf13/cobra" ) @@ -47,7 +49,22 @@ func installRun(_ *cobra.Command, args []string) error { } func surveyScriptDir() (string, error) { - return "", nil + home, err := os.UserHomeDir() + if err != nil { + return "", err + } + + var scriptDir string + p := &survey.Input{ + Message: "Please enter qpm script path.", + Default: filepath.Join(home, ".qpm"), + } + err = survey.AskOne(p, &scriptDir, survey.WithValidator(survey.Required)) + if err != nil { + return "", err + } + + return scriptDir, nil } func getPkgName(args []string) (string, error) { @@ -68,6 +85,11 @@ func getInstallScriptPaht(scriptDir, pkgName string) (string, error) { } func execInstallScript(installScriptPath string) error { + _, err := os.Stat(installScriptPath) + if os.IsNotExist(err) { + return fmt.Errorf("install script not found: %s", installScriptPath) + } + o, err := exec.Command("/bin/sh", installScriptPath).Output() if err != nil { return err