Skip to content

Commit bea590f

Browse files
authored
devbox: export API for devbox install (#2437)
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 (similar to what we're doing with autodetect).
1 parent e0a87e5 commit bea590f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

devbox.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package devbox creates and configures Devbox development environments.
2+
package devbox
3+
4+
import (
5+
"context"
6+
"io"
7+
8+
"go.jetpack.io/devbox/internal/devbox"
9+
"go.jetpack.io/devbox/internal/devbox/devopt"
10+
)
11+
12+
// Devbox is a Devbox development environment.
13+
type Devbox struct {
14+
dx *devbox.Devbox
15+
}
16+
17+
// Open loads a Devbox environment from a config file or directory.
18+
func Open(path string) (*Devbox, error) {
19+
dx, err := devbox.Open(&devopt.Opts{
20+
Dir: path,
21+
Stderr: io.Discard,
22+
})
23+
if err != nil {
24+
return nil, err
25+
}
26+
return &Devbox{dx: dx}, nil
27+
}
28+
29+
// Install downloads and installs missing packages.
30+
func (d *Devbox) Install(ctx context.Context) error {
31+
return d.dx.Install(ctx)
32+
}

0 commit comments

Comments
 (0)