Skip to content

internal/devconfig: move project directory search into devbox.Find #2172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ linters-settings:
- name: bare-return
- name: bool-literal-in-expr
- name: cognitive-complexity
exclude:
- "**_test.go"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

arguments:
- 32 # TODO: gradually reduce it
- name: datarace
Expand Down
24 changes: 17 additions & 7 deletions internal/devbox/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,24 @@ func InitConfig(dir string) (bool, error) {
}

func Open(opts *devopt.Opts) (*Devbox, error) {
projectDir, err := findProjectDir(opts.Dir)
if err != nil {
return nil, err
var cfg *devconfig.Config
var err error
if opts.Dir == "" {
cfg, err = devconfig.Find(".")
if errors.Is(err, devconfig.ErrNotFound) {
return nil, usererr.New("no devbox.json found in the current directory (or any parent directories). Did you run `devbox init` yet?")
}
} else {
cfg, err = devconfig.Open(opts.Dir)
if errors.Is(err, os.ErrNotExist) {
return nil, usererr.New("the devbox config path %q does not exist.", opts.Dir)
}
if errors.Is(err, devconfig.ErrNotFound) {
return nil, usererr.New("no devbox.json found in %q. Did you run `devbox init` yet?", opts.Dir)
}
}

cfg, err := devconfig.Open(projectDir)
if err != nil {
return nil, errors.WithStack(err)
return nil, usererr.WithUserMessage(err, "Error loading devbox.json.")
}

environment, err := validateEnvironment(opts.Environment)
Expand All @@ -96,7 +106,7 @@ func Open(opts *devopt.Opts) (*Devbox, error) {
env: opts.Env,
environment: environment,
nix: &nix.Nix{},
projectDir: projectDir,
projectDir: filepath.Dir(cfg.Root.AbsRootPath),
pluginManager: plugin.NewManager(),
stderr: opts.Stderr,
customProcessComposeFile: opts.CustomProcessComposeFile,
Expand Down
113 changes: 0 additions & 113 deletions internal/devbox/dir.go

This file was deleted.

141 changes: 0 additions & 141 deletions internal/devbox/dir_test.go

This file was deleted.

Loading