Skip to content

Commit 4b2f0c8

Browse files
authored
[runx] Install should return paths (#150)
## Summary Stacked on #149 `runx.Install` should return the path where binaries are installed. In the future I think we can make this API a bit better by making it typed. e.g. ```golang runx.install(git.Repo{ Provider: git.GithubProvider, User: "jetpack-io", Name: "envsec", }) ``` ## How was it tested? runx --install jetpack-io/envsec
1 parent e08d7d9 commit 4b2f0c8

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

pkg/sandbox/runx/cmd/runx/cli/root.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"context"
5+
"flag"
56
"fmt"
67
"os"
78

@@ -13,7 +14,10 @@ func Help() {
1314
c := color.New(color.FgCyan).Add(color.Underline)
1415
c.Println("runx")
1516
fmt.Println()
16-
fmt.Println("Usage: runx [+<org>/<repo>]... [<cmd>] [<args>]...")
17+
fmt.Println(
18+
"Usage: runx [+<org>/<repo>]... [<cmd>] [<args>]...",
19+
"Usage: runx --install [<org>/<repo>]...",
20+
)
1721
}
1822

1923
func Execute(ctx context.Context, args []string) int {
@@ -22,11 +26,26 @@ func Execute(ctx context.Context, args []string) int {
2226
return 0
2327
}
2428

25-
err := runx.Run(args...)
26-
if err != nil {
27-
fmt.Fprintf(os.Stderr, "[ERROR] %s\n", err)
28-
return 1
29+
install := flag.Bool("install", false, "install packages only")
30+
flag.Parse()
31+
32+
if *install {
33+
paths, err := runx.Install(args[1:]...)
34+
if err != nil {
35+
fmt.Fprintf(os.Stderr, "[ERROR] %s\n", err)
36+
return 1
37+
}
38+
fmt.Println("Installed paths:")
39+
for _, path := range paths {
40+
fmt.Printf(" %s\n", path)
41+
}
42+
} else {
43+
if err := runx.Run(args...); err != nil {
44+
fmt.Fprintf(os.Stderr, "[ERROR] %s\n", err)
45+
return 1
46+
}
2947
}
48+
3049
return 0
3150
}
3251

pkg/sandbox/runx/runx.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"go.jetpack.io/pkg/sandbox/runx/impl"
55
)
66

7-
func Install(pkgs ...string) error {
8-
_, err := impl.Install(pkgs...)
9-
return err
7+
// Install installs the given packages and returns the paths to the directories
8+
// where they were installed.
9+
func Install(pkgs ...string) ([]string, error) {
10+
return impl.Install(pkgs...)
1011
}
1112

1213
func Run(args ...string) error {

0 commit comments

Comments
 (0)