From dd15c7ee1434d0f28d4a72540917095d915bfe2c Mon Sep 17 00:00:00 2001 From: Greg Curtis Date: Thu, 5 Dec 2024 12:06:23 -0500 Subject: [PATCH] devbox: export API for devbox install Add a top-level package that makes a subset of the `internal/devbox` functionality (currently just install) public. There are some places where we want to run devbox commands (such as in the prefetcher) which requires us to run the CLI externally. Exporting a package means we can run the command implementation directly and don't need to install the CLI. --- devbox.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 devbox.go diff --git a/devbox.go b/devbox.go new file mode 100644 index 00000000000..410f6faaf22 --- /dev/null +++ b/devbox.go @@ -0,0 +1,32 @@ +// Package devbox creates and configures Devbox development environments. +package devbox + +import ( + "context" + "io" + + "go.jetpack.io/devbox/internal/devbox" + "go.jetpack.io/devbox/internal/devbox/devopt" +) + +// Devbox is a Devbox development environment. +type Devbox struct { + dx *devbox.Devbox +} + +// Open loads a Devbox environment from a config file or directory. +func Open(path string) (*Devbox, error) { + dx, err := devbox.Open(&devopt.Opts{ + Dir: path, + Stderr: io.Discard, + }) + if err != nil { + return nil, err + } + return &Devbox{dx: dx}, nil +} + +// Install downloads and installs missing packages. +func (d *Devbox) Install(ctx context.Context) error { + return d.dx.Install(ctx) +}