jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
7.83k stars 187 forks source link

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

Open gcurtis opened 1 week ago

gcurtis commented 1 week ago

Instead of first searching for a project directory and then calling devbox.Open on that path, add a devbox.Find method that performs the search and open as a single step.

// Open loads a Devbox config from a file or project directory.
// For use with `devbox -c some/dir <subcmd>`.
func Open(path string) (*Config, error)

// Find is like [Open] except it recursively searches up the directory tree.
// For use with `devbox <subcmd>` (without a `-c` flag).
func Find(path string) (*Config, error)

Changes to user error messages:

 $ devbox add go

-Error: No devbox.json found in this directory, or any parent directories. Did you run `devbox init` yet?
+Error: no devbox.json found in the current directory (or any parent directories). Did you run `devbox init` yet?

 $ devbox -c badpath add go
-Error: stat /var/folders/79/1yc1ywp10w9f2xnr_rpp_ff00000gn/T/tmp.bU25JVWovO/badpath: no such file or directory
+
+Error: the devbox config path "badpath" does not exist.

 $ mkdir child
 $ devbox -c child add go

-Error: No devbox.json found in child. Did you run `devbox init` yet?
+Error: no devbox.json found in "child". Did you run `devbox init` yet?