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: ftl new and ftl init updates #3930

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/provisioner/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func provisionerIDToProvisioner(ctx context.Context, id string, controller ftlv1
default:
plugin, _, err := plugin.Spawn(
ctx,
log.Debug,
log.FromContext(ctx).GetLevel(),
"ftl-provisioner-"+id,
".",
"ftl-provisioner-"+id,
Expand Down
6 changes: 2 additions & 4 deletions docs/content/docs/getting-started/quick-start/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ The [FTL VSCode extension](https://marketplace.visualstudio.com/items?itemName=F
Once FTL is installed, initialize an FTL project:

```
mkdir myproject
ftl init myproject
cd myproject
ftl init myproject .
```

This will create an `ftl-project.toml` file, a git repository, and a `bin/` directory with Hermit tooling. The Hermit tooling
includes the current version of FTL, and language support for go and JVM based languages.
This will create a new `myproject` directory containing an `ftl-project.toml` file, a git repository, and a `bin/` directory with Hermit tooling. The Hermit tooling includes the current version of FTL, and language support for go and JVM based languages.

### Create a new module

Expand Down
26 changes: 25 additions & 1 deletion frontend/cli/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,38 @@ var userHermitPackages string

type initCmd struct {
Name string `arg:"" help:"Name of the project."`
Dir string `arg:"" optional:"" help:"Directory to initialize the project in. If not specified, creates a new directory with the project name."`
Hermit bool `help:"Include Hermit language-specific toolchain binaries." negatable:"" default:"true"`
Dir string `arg:"" help:"Directory to initialize the project in." default:"." required:""`
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."`
Startup string `help:"Command to run on startup."`
}

func (i initCmd) Help() string {
return `
Examples:
ftl init myproject # Creates a new folder named "myproject" and initializes it
ftl init myproject . # Initializes the current directory as "myproject"
ftl init myproject custom # Creates a folder named "custom" and initializes it as "myproject"`
}

func (i initCmd) Run(
ctx context.Context,
logger *log.Logger,
configRegistry *providers.Registry[configuration.Configuration],
secretsRegistry *providers.Registry[configuration.Secrets],
) error {
// If the directory is not specified, use the project name as the directory name.
if i.Dir == "" {
i.Dir = i.Name
}

logger.Debugf("Initializing FTL project in %s", i.Dir)
if err := os.MkdirAll(i.Dir, 0750); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}

if err := scaffold(ctx, i.Hermit, projectinit.Files(), i.Dir, i); err != nil {
return err
}
Expand Down Expand Up @@ -101,6 +118,13 @@ func (i initCmd) Run(
}
}
}

fmt.Printf("Successfully created FTL project '%s' in %s\n\n", i.Name, i.Dir)
fmt.Printf("To get started:\n")
if i.Dir != "." {
fmt.Printf(" cd %s\n", i.Dir)
}
fmt.Printf(" ftl dev\n")
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/cli/cmd_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (i newCmd) Run(ctx context.Context, ktctx *kong.Context, config projectconf
}
}
_ = plugin.Kill() //nolint:errcheck

fmt.Printf("Successfully created %s module %q in %s\n", i.Language, name, path)
return nil
}

Expand Down
7 changes: 5 additions & 2 deletions frontend/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ func main() {

app := createKongApplication(&cli, csm)

// Dynamically update the kong app with language specific flags for the "ftl new" command.
languagePlugin, err := languageplugin.PrepareNewCmd(log.ContextWithNewDefaultLogger(ctx), app, os.Args[1:])
err := kong.ApplyDefaults(&cli.LogConfig)
app.FatalIfErrorf(err)

pluginCtx := log.ContextWithLogger(ctx, log.Configure(os.Stderr, cli.LogConfig))
languagePlugin, err := languageplugin.PrepareNewCmd(pluginCtx, app, os.Args[1:])
app.FatalIfErrorf(err)
addToExit(app, func(code int) {
// Kill the plugin when the app exits due to an error, or after showing help.
Expand Down
2 changes: 1 addition & 1 deletion jvm-runtime/jvm_hot_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestLifecycleJVM(t *testing.T) {
in.WithDevMode(),
in.GitInit(),
in.Exec("rm", "ftl-project.toml"),
in.Exec("ftl", "init", "test"),
in.Exec("ftl", "init", "test", "."),
in.IfLanguage("java", in.Exec("ftl", "new", "java", "echo")),
in.IfLanguage("kotlin", in.Exec("ftl", "new", "kotlin", "echo")),
in.WaitWithTimeout("echo", time.Minute),
Expand Down
Loading