MCPcopy Index your code
hub / github.com/jetify-com/devbox / Open

Function Open

internal/devbox/devbox.go:92–179  ·  view source on GitHub ↗
(opts *devopt.Opts)

Source from the content-addressed store, hash-verified

90}
91
92func Open(opts *devopt.Opts) (*Devbox, error) {
93 var cfg *devconfig.Config
94 var err error
95 if opts.Dir == "" {
96 cfg, err = devconfig.Find(".")
97 if errors.Is(err, devconfig.ErrNotFound) {
98 return nil, usererr.New("no devbox.json found in the current directory (or any parent directories). Did you run `devbox init` yet?")
99 }
100 } else {
101 cfg, err = devconfig.Open(opts.Dir)
102 if errors.Is(err, os.ErrNotExist) {
103 return nil, usererr.New("the devbox config path %q does not exist.", opts.Dir)
104 }
105 if errors.Is(err, devconfig.ErrNotFound) {
106 return nil, usererr.New("no devbox.json found in %q. Did you run `devbox init` yet?", opts.Dir)
107 }
108 }
109 if err != nil {
110 return nil, usererr.WithUserMessage(err, "Error loading devbox.json.")
111 }
112
113 environment, err := validateEnvironment(opts.Environment)
114 if err != nil {
115 return nil, err
116 }
117
118 box := &Devbox{
119 cfg: cfg,
120 env: opts.Env,
121 environment: environment,
122 nix: &nix.NixInstance{},
123 projectDir: filepath.Dir(cfg.Root.AbsRootPath),
124 pluginManager: plugin.NewManager(),
125 stderr: opts.Stderr,
126 customProcessComposeFile: opts.CustomProcessComposeFile,
127 }
128
129 lock, err := lock.GetFile(box)
130 if err != nil {
131 return nil, err
132 }
133
134 if err := cfg.LoadRecursive(lock); err != nil {
135 return nil, err
136 }
137
138 // if lockfile has any allow insecure, we need to set the env var to ensure
139 // all nix commands work.
140 if err := box.moveAllowInsecureFromLockfile(box.stderr, lock, cfg); err != nil {
141 ux.Fwarningf(
142 box.stderr,
143 "Failed to move allow_insecure from devbox.lock to devbox.json. An insecure package may "+
144 "not work until you invoke `devbox add <pkg> --allow-insecure=<packages>` again: %s\n",
145 err,
146 )
147 // continue on, since we do not want to block user.
148 }
149

Callers 15

OpenFunction · 0.92
ensureGlobalEnvEnabledFunction · 0.92
pushCmdFuncFunction · 0.92
cacheCmdFunction · 0.92
envsecMethod · 0.92
secretsInitFuncFunction · 0.92
updateCmdFuncFunction · 0.92
pullCmdFuncFunction · 0.92
whoAmICmdFunction · 0.92
shellEnvFuncFunction · 0.92
installCmdFuncFunction · 0.92
infoCmdFuncFunction · 0.92

Calls 15

LoadRecursiveMethod · 0.95
HasDeprecatedPackagesMethod · 0.95
FindFunction · 0.92
NewFunction · 0.92
OpenFunction · 0.92
WithUserMessageFunction · 0.92
NewManagerFunction · 0.92
GetFileFunction · 0.92
FwarningfFunction · 0.92
WithDevboxFunction · 0.92
WithLockfileFunction · 0.92

Tested by 4

testShellPlanFunction · 0.56
devboxForTestingFunction · 0.56
TestShellPathFunction · 0.56