From 670c1df98e0c5a330f979fea430d974333230211 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 2 Jan 2025 16:54:02 -0500 Subject: [PATCH] Use gel.toml if one exists (#327) --------- Co-authored-by: Frederick --- cmd/edgeql-go/main.go | 10 +++++++- internal/client/connutils.go | 50 +++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/cmd/edgeql-go/main.go b/cmd/edgeql-go/main.go index d85fc9c..d5373a1 100644 --- a/cmd/edgeql-go/main.go +++ b/cmd/edgeql-go/main.go @@ -162,12 +162,20 @@ func getProject() (*project, error) { ) } - file := filepath.Join(dir, "edgedb.toml") + file := filepath.Join(dir, "gel.toml") isTOML, err := isEdgeDBTOML(file) if err != nil { return nil, err } + if !isTOML { + file = filepath.Join(dir, "edgedb.toml") + isTOML, err = isEdgeDBTOML(file) + if err != nil { + return nil, err + } + } + if isTOML { data, err := os.ReadFile(file) if err != nil { diff --git a/internal/client/connutils.go b/internal/client/connutils.go index 68b7938..69f0663 100644 --- a/internal/client/connutils.go +++ b/internal/client/connutils.go @@ -917,7 +917,7 @@ func (r *configResolver) resolveTOML(paths *cfgPaths) error { } if !exists(stashDir) { - return errors.New("Found `edgedb.toml` " + + return errors.New("Found `gel.toml` " + "but the project is not initialized. Run `edgedb project init`.") } @@ -1465,33 +1465,37 @@ func findEdgeDBTOML(paths *cfgPaths) (string, error) { } for { - tomlPath := filepath.Join(dir, "edgedb.toml") + tomlPath := filepath.Join(dir, "gel.toml") if _, e := os.Stat(tomlPath); os.IsNotExist(e) { - parent := filepath.Dir(dir) - // Stop searching when dir is the root directory. - if parent == dir { - return "", errNoTOMLFound - } + tomlPath = filepath.Join(dir, "edgedb.toml") + if _, e := os.Stat(tomlPath); os.IsNotExist(e) { + parent := filepath.Dir(dir) + // Stop searching when dir is the root directory. + if parent == dir { + return "", errNoTOMLFound + } - pDev, err := device(parent) - if err != nil { - return "", fmt.Errorf( - "searching for edgedb.toml in or above %q: %w", - filepath.Dir(tomlPath), err) - } + pDev, err := device(parent) + if err != nil { + return "", fmt.Errorf( + "searching for gel.toml in or above %q: %w", + filepath.Dir(tomlPath), err) + } - // Stop searching at file system boundaries. - if pDev != dev { - if err == nil { // nolint:govet - err = errNoTOMLFound + // Stop searching at file system boundaries. + if pDev != dev { + if err == nil { // nolint:govet + err = errNoTOMLFound + } + return "", fmt.Errorf( + "%w: stopped searching for gel.toml "+ + "at file system boundary %q", err, dir) } - return "", fmt.Errorf("%w: stopped searching for edgedb.toml "+ - "at file system boundary %q", err, dir) - } - dir = parent - dev = pDev - continue + dir = parent + dev = pDev + continue + } } return tomlPath, nil }