Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate ftl-project.toml in the Git root if it DNE #1648

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

deniseli
Copy link
Contributor

@deniseli deniseli commented Jun 4, 2024

Fixes #1639

The current implementation ignores any --config flag values, but let me know if we should default to creating the last specified config whenever one's provided. For that, I'd just move this code to the resolver and add an r.Config check. I decided to minimize it purely to operating on the default path because the specified paths may not actually be at the Git root, which could make the new behavior a bit more complex to comprehend. That said, there could be a good reason to use the flag value that I didn't think of.

@ftl-robot ftl-robot mentioned this pull request Jun 4, 2024
@deniseli deniseli marked this pull request as ready for review June 4, 2024 19:13
@deniseli deniseli requested a review from alecthomas as a code owner June 4, 2024 19:13
@deniseli deniseli requested review from a team and wesbillman and removed request for a team June 4, 2024 19:13
@deniseli
Copy link
Contributor Author

deniseli commented Jun 4, 2024

The failing integration test is broken on main at the moment. I'll rebase once after the fix goes in :)

// CreateDefaultFileIfNonexistent creates the ftl-project.toml file in the Git root if it
// does not already exist.
func CreateDefaultFileIfNonexistent(ctx context.Context) error {
path := GetDefaultConfigPath()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately GitRoot() can return an empty string, so this can be incorrect. Would you mind converting that function and GetDefaultConfigPath() to use Option[string] so this is more obvious in the future? You'll need to cater to this here as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what we should do if we can't find the git root...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, will do. I'll add a warning for that branch case until we come up with something better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let me know what you think of the behavior for all the other GitRoot callers... I defaulted to preserving the old behavior wherever the right choice was ambiguous. At least it's obvious now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another consideration is whether to pass through the original error from GitRoot returning (string, error), but I left it as the optional for now.

gitRoot := internal.GitRoot(dir)
gitRoot, ok := internal.GitRoot(dir).Get()
if !ok {
gitRoot = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just return nil no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh yes, fixed

}

func GetDefaultConfigPath() string {
return filepath.Join(internal.GitRoot(""), "ftl-project.toml")
func GetDefaultConfigPath() optional.Option[string] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Idiomatic Go is to not use "getter" style naming, I'd just call this DefaultConfigPath().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

logger := log.FromContext(ctx)
path, ok := GetDefaultConfigPath().Get()
if !ok {
logger.Warnf("Failed to find Git root, so cannot verify whether an ftl-project.toml file exists there")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@deniseli deniseli merged commit 71fde02 into main Jun 5, 2024
32 checks passed
@deniseli deniseli deleted the dli/init-config branch June 5, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ftl-project.toml should be generated if doesn't exist when running ftl init
2 participants