Skip to content

Commit

Permalink
fix: ftl new uses project root as dir (#3412)
Browse files Browse the repository at this point in the history
fixes #3012
  • Loading branch information
matt2e authored Nov 19, 2024
1 parent e17d58d commit eb58f67
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions frontend/cli/cmd_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ func prepareNewCmd(ctx context.Context, k *kong.Kong, args []string) (optionalPl
return optionalPlugin, fmt.Errorf("could not find new command")
}

plugin, err := languageplugin.New(ctx, pluginDir(), language, "new")
projConfigPath, ok := projectconfig.DefaultConfigPath().Get()
if !ok {
return optionalPlugin, fmt.Errorf("could not find project config path")
}
_, err = projectconfig.Load(ctx, projConfigPath)
if err != nil {
if os.IsNotExist(err) {
return optionalPlugin, fmt.Errorf(`could not find FTL project config: try running "ftl init"`)
}
return optionalPlugin, fmt.Errorf("could not load project config: %w", err)
}

plugin, err := languageplugin.New(ctx, filepath.Dir(projConfigPath), language, "new")
if err != nil {
return optionalPlugin, fmt.Errorf("could not create plugin for %v: %w", language, err)
}
Expand All @@ -80,15 +92,6 @@ func prepareNewCmd(ctx context.Context, k *kong.Kong, args []string) (optionalPl
return optional.Some(plugin), nil
}

// pluginDir returns the directory to base the plugin working directory off of.
// It tries to find the root directory of the project, or uses "." as a fallback.
func pluginDir() string {
if configPath, ok := projectconfig.DefaultConfigPath().Get(); ok {
return filepath.Dir(configPath)
}
return "."
}

func (i newCmd) Run(ctx context.Context, ktctx *kong.Context, config projectconfig.Config, plugin *languageplugin.LanguagePlugin) error {
name, path, err := validateModule(i.Dir, i.Name)
if err != nil {
Expand Down

0 comments on commit eb58f67

Please sign in to comment.