From 832e359b0e7310367c15d94a4ce85f05866491b9 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 13 Jun 2024 09:58:32 +1000 Subject: [PATCH] fix: require an ftl-project.toml file This is a global requirement across all commands, not scoped specifically to `ftl serve` or `ftl dev`, because eg. `ftl secret`/`ftl config`, etc. etc. all require this config file, and it's just cleaner/safer to do it in one location. Fixes #1669 --- cmd/ftl/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/ftl/main.go b/cmd/ftl/main.go index 9ef5764794..4e555985eb 100644 --- a/cmd/ftl/main.go +++ b/cmd/ftl/main.go @@ -84,14 +84,23 @@ func main() { logger := log.Configure(os.Stderr, cli.LogConfig) ctx = log.ContextWithLogger(ctx, logger) - config, err := projectconfig.Load(ctx, cli.ConfigFlag) + configPath := cli.ConfigFlag + if configPath == "" { + var ok bool + configPath, ok = projectconfig.DefaultConfigPath().Get() + if !ok { + kctx.Fatalf("could not determine default config path, place an ftl-project.toml file in your git root directory, use --config=FILE, or set the FTL_CONFIG envar") + } + } + + config, err := projectconfig.Load(ctx, configPath) if err != nil && !errors.Is(err, os.ErrNotExist) { kctx.Fatalf(err.Error()) } kctx.Bind(config) - sr := cf.ProjectConfigResolver[cf.Secrets]{Config: cli.ConfigFlag} - cr := cf.ProjectConfigResolver[cf.Configuration]{Config: cli.ConfigFlag} + sr := cf.ProjectConfigResolver[cf.Secrets]{Config: configPath} + cr := cf.ProjectConfigResolver[cf.Configuration]{Config: configPath} kctx.BindTo(sr, (*cf.Resolver[cf.Secrets])(nil)) kctx.BindTo(cr, (*cf.Resolver[cf.Configuration])(nil))