diff --git a/internal/vscode/cli.go b/internal/vscode/cli.go index de7561b..98857a0 100644 --- a/internal/vscode/cli.go +++ b/internal/vscode/cli.go @@ -1,11 +1,14 @@ package vscode import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "regexp" "runtime" + "strings" "github.com/recode-sh/cli/internal/system" ) @@ -27,9 +30,29 @@ func (c CLI) Exec(arg ...string) (string, error) { return "", err } - cmdOutput, err := exec.Command(CLIPath, arg...).CombinedOutput() + cmd := exec.Command(CLIPath, arg...) - return string(cmdOutput), err + var stdout bytes.Buffer + var stderr bytes.Buffer + + cmd.Stdout = &stdout + cmd.Stderr = &stderr + + err = cmd.Run() + + if err != nil { + newLineRegExp := regexp.MustCompile(`\n+`) + + return "", fmt.Errorf( + "Error while calling the Visual Studio Code CLI:\n\n%s\n\n%s", + strings.TrimSpace( + newLineRegExp.ReplaceAllLiteralString(stderr.String(), " "), + ), + err.Error(), + ) + } + + return stdout.String(), nil } func (c CLI) LookupPath(operatingSystem string) (string, error) { diff --git a/internal/vscode/extensions.go b/internal/vscode/extensions.go index 42a33cb..860957c 100644 --- a/internal/vscode/extensions.go +++ b/internal/vscode/extensions.go @@ -8,5 +8,10 @@ func NewExtensions() Extensions { func (e Extensions) Install(extensionName string) (string, error) { c := CLI{} - return c.Exec("--install-extension", extensionName, "--force") + + return c.Exec( + "--install-extension", + extensionName, + "--force", + ) } diff --git a/internal/vscode/process.go b/internal/vscode/process.go index 5a6fff5..dfcd70a 100644 --- a/internal/vscode/process.go +++ b/internal/vscode/process.go @@ -8,6 +8,7 @@ func NewProcess() Process { func (p Process) OpenOnRemote(hostKey, pathToOpen string) (string, error) { c := CLI{} + return c.Exec( "--new-window", "--skip-release-notes",