diff --git a/pkg/sandbox/runx/.gitignore b/pkg/sandbox/runx/.gitignore new file mode 100644 index 00000000..1521c8b7 --- /dev/null +++ b/pkg/sandbox/runx/.gitignore @@ -0,0 +1 @@ +dist diff --git a/pkg/sandbox/runx/cmd/runx/cli/root.go b/pkg/sandbox/runx/cmd/runx/cli/root.go index c9085dec..4206a225 100644 --- a/pkg/sandbox/runx/cmd/runx/cli/root.go +++ b/pkg/sandbox/runx/cmd/runx/cli/root.go @@ -2,6 +2,7 @@ package cli import ( "context" + "flag" "fmt" "os" @@ -13,7 +14,10 @@ func Help() { c := color.New(color.FgCyan).Add(color.Underline) c.Println("runx") fmt.Println() - fmt.Println("Usage: runx [+/]... [] []...") + fmt.Println( + "Usage: runx [+/]... [] []...", + "Usage: runx --install [/]...", + ) } func Execute(ctx context.Context, args []string) int { @@ -22,11 +26,26 @@ func Execute(ctx context.Context, args []string) int { return 0 } - err := runx.Run(args...) - if err != nil { - fmt.Fprintf(os.Stderr, "[ERROR] %s\n", err) - return 1 + install := flag.Bool("install", false, "install packages only") + flag.Parse() + + if *install { + paths, err := runx.Install(args[1:]...) + if err != nil { + fmt.Fprintf(os.Stderr, "[ERROR] %s\n", err) + return 1 + } + fmt.Println("Installed paths:") + for _, path := range paths { + fmt.Printf(" %s\n", path) + } + } else { + if err := runx.Run(args...); err != nil { + fmt.Fprintf(os.Stderr, "[ERROR] %s\n", err) + return 1 + } } + return 0 } diff --git a/pkg/sandbox/runx/devbox.json b/pkg/sandbox/runx/devbox.json new file mode 100644 index 00000000..79d2ae97 --- /dev/null +++ b/pkg/sandbox/runx/devbox.json @@ -0,0 +1,10 @@ +{ + "packages": [ + "go@latest" + ], + "shell": { + "scripts": { + "build": "go build -o dist/runx cmd/runx/main.go" + } + } +} diff --git a/pkg/sandbox/runx/devbox.lock b/pkg/sandbox/runx/devbox.lock new file mode 100644 index 00000000..28a53dbe --- /dev/null +++ b/pkg/sandbox/runx/devbox.lock @@ -0,0 +1,25 @@ +{ + "lockfile_version": "1", + "packages": { + "go@latest": { + "last_modified": "2023-09-17T10:54:49Z", + "resolved": "github:NixOS/nixpkgs/5148520bfab61f99fd25fb9ff7bfbb50dad3c9db#go_1_21", + "source": "devbox-search", + "version": "1.21.1", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/jkhg33806wygpwpix47d2h5scfgn01i8-go-1.21.1" + }, + "aarch64-linux": { + "store_path": "/nix/store/sgkkfw6saficch0mviqyqyw6nj64kzf9-go-1.21.1" + }, + "x86_64-darwin": { + "store_path": "/nix/store/w67nj5iqgnz0msi8i12kyh9nhsp2ci9n-go-1.21.1" + }, + "x86_64-linux": { + "store_path": "/nix/store/jk0bqfsjijia52vks1wxqnn4s6dxaiqp-go-1.21.1" + } + } + } + } +} diff --git a/pkg/sandbox/runx/runx.go b/pkg/sandbox/runx/runx.go index c2c005eb..261f60fe 100644 --- a/pkg/sandbox/runx/runx.go +++ b/pkg/sandbox/runx/runx.go @@ -4,9 +4,10 @@ import ( "go.jetpack.io/pkg/sandbox/runx/impl" ) -func Install(pkgs ...string) error { - _, err := impl.Install(pkgs...) - return err +// Install installs the given packages and returns the paths to the directories +// where they were installed. +func Install(pkgs ...string) ([]string, error) { + return impl.Install(pkgs...) } func Run(args ...string) error {