Skip to content

Commit

Permalink
fix: barry 2024-10-29 10:00:50
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Oct 29, 2024
1 parent 6dcf24f commit 5ac8ce8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmd/protobuild/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/fs"
"log/slog"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -478,12 +479,23 @@ func Main() *cli.Command {
defer recovery.Exit()

for _, plg := range globalCfg.Installers {
if !strings.Contains(plg, "@") || force {
if strings.Contains(plg, "@") {
pluginPaths := strings.Split(plg, "@")
plg = strings.Join(pluginPaths[:len(pluginPaths)-1], "@") + "@latest"
}
if !strings.Contains(plg, "@") {
pluginPaths := strings.Split(plg, "@")
plg = strings.Join(pluginPaths[:len(pluginPaths)-1], "@") + "@latest"
}

plgName := strings.Split(lo.LastOrEmpty(strings.Split(plg, "/")), "@")[0]
path, err := exec.LookPath(plgName)
if err != nil {
slog.Error("command not found", slog.Any("name", plgName))
}

if err == nil && !force {
slog.Info("command path", slog.Any("path", path))
continue
}

slog.Info("install command", slog.Any("name", plg))
assert.Must(shutil.Shell("go", "install", plg).Run())
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions internal/shutil/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shutil

import (
"bytes"
"log/slog"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -36,6 +37,7 @@ func GoList() (string, error) {

func Shell(args ...string) *exec.Cmd {
shell := strings.Join(args, " ")
slog.Info(shell)
cmd := exec.Command("/bin/sh", "-c", shell)
cmd.Env = os.Environ()
cmd.Stdout = os.Stdout
Expand Down

0 comments on commit 5ac8ce8

Please sign in to comment.