Skip to content

Commit

Permalink
chore: port some more profile fields from projectconfig (#4265)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored Feb 3, 2025
1 parent bf0a8a7 commit c4a6283
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cmd/ftl/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type initCmd struct {
Hermit bool `help:"Include Hermit language-specific toolchain binaries." negatable:"" default:"true"`
ModuleDirs []string `help:"Child directories of existing modules."`
ModuleRoots []string `help:"Root directories of existing modules."`
NoGit bool `help:"Don't add files to the git repository."`
Git bool `help:"Commit generated files to git." negatable:"" default:"true"`
Startup string `help:"Command to run on startup."`
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func (i initCmd) Run(
config := projectconfig.Config{
Name: i.Name,
Hermit: i.Hermit,
NoGit: i.NoGit,
NoGit: !i.Git,
FTLMinVersion: ftl.Version,
ModuleDirs: i.ModuleDirs,
Commands: projectconfig.Commands{
Expand All @@ -82,7 +82,7 @@ func (i initCmd) Run(
Realm: i.Name,
FTLMinVersion: ftl.Version,
ModuleRoots: i.ModuleRoots,
NoGit: i.NoGit,
Git: !i.Git,
Root: i.Dir,
}, secretsRegistry, configRegistry)
if err != nil {
Expand All @@ -94,7 +94,7 @@ func (i initCmd) Run(
}
}

if !i.NoGit {
if i.Git {
err := maybeGitInit(ctx, i.Dir)
if err != nil {
return fmt.Errorf("running git init: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/ftl/cmd_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (p profileInitCmd) Run(
Realm: p.Project,
FTLMinVersion: ftl.Version,
ModuleRoots: p.ModuleRoots,
NoGit: p.NoGit,
Git: !p.NoGit,
Root: p.Dir,
}, secretsRegistry, configRegistry)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/go2proto/testdata/testdatapb/model.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/profiles/internal/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ type Project struct {
Realm string `json:"realm"`
FTLMinVersion string `json:"ftl-min-version,omitempty"`
ModuleRoots []string `json:"module-roots,omitempty"`
NoGit bool `json:"no-git,omitempty"`
Git bool `json:"git,omitempty"`
Hermit bool `json:"hermit,omitempty"`
DefaultProfile string `json:"default-profile,omitempty"`

Root string `json:"-"`
Expand Down
27 changes: 24 additions & 3 deletions internal/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/block/ftl/common/slices"
"github.com/block/ftl/internal/configuration"
Expand All @@ -19,15 +21,34 @@ import (
//
// It mirrors the internal.Project struct.
type ProjectConfig struct {
Realm string `json:"realm"`
FTLMinVersion string `json:"ftl-min-version,omitempty"`
Realm string `json:"realm"`
FTLMinVersion string `json:"ftl-min-version,omitempty"`
// ModuleRoots is a list of directories that contain modules.
ModuleRoots []string `json:"module-roots,omitempty"`
NoGit bool `json:"no-git,omitempty"`
Git bool `json:"git,omitempty"`
Hermit bool `json:"hermit,omitempty"`
DefaultProfile string `json:"default-profile,omitempty"`

Root string `json:"-"`
}

// AbsModuleDirs returns the absolute path for the module-dirs field from the ftl-project.toml, unless
// that is not defined, in which case it defaults to the root directory.
func (c ProjectConfig) AbsModuleDirs() []string {
if len(c.ModuleRoots) == 0 {
return []string{c.Root}
}
absDirs := make([]string, len(c.ModuleRoots))
for i, dir := range c.ModuleRoots {
cleaned := filepath.Clean(filepath.Join(c.Root, dir))
if !strings.HasPrefix(cleaned, c.Root) {
panic(fmt.Errorf("module-dirs path %q is not within the project root %q", dir, c.Root))
}
absDirs[i] = cleaned
}
return absDirs
}

type Profile struct {
shared ProjectConfig
name string
Expand Down
2 changes: 0 additions & 2 deletions internal/profiles/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestProfile(t *testing.T) {
Realm: "test",
FTLMinVersion: ftl.Version,
ModuleRoots: []string{"."},
NoGit: true,
}
sr := providers.NewRegistry[configuration.Secrets]()
sr.Register(providers.NewInlineFactory[configuration.Secrets]())
Expand All @@ -48,7 +47,6 @@ func TestProfile(t *testing.T) {
Realm: "test",
FTLMinVersion: ftl.Version,
ModuleRoots: []string{"."},
NoGit: true,
DefaultProfile: "local",
}, profile.ProjectConfig())

Expand Down

0 comments on commit c4a6283

Please sign in to comment.