Skip to content

Commit

Permalink
Move project init to APIs (#2484)
Browse files Browse the repository at this point in the history
* initial commit

* initial commit

* adding proto

* unpack changes

* remove examples dir

* adding .gitkeep file

* review changes plus additional changes

* moving project variable creation to reconcile

* fixing tests

* removing unused code

* review comments

* review comments

* Regenerate clients

* unpack empty api

* unpack empty api

* review comments - unpack api

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
  • Loading branch information
k-anshul and begelundmuller authored May 24, 2023
1 parent 9a9e528 commit c1cb889
Show file tree
Hide file tree
Showing 50 changed files with 3,286 additions and 1,346 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ cli.prepare:
rm -rf cli/pkg/web/embed/dist || true
mkdir -p cli/pkg/web/embed/dist
cp -r web-local/build/* cli/pkg/web/embed/dist
rm -rf cli/pkg/examples/embed/dist || true
mkdir -p cli/pkg/examples/embed/dist
cp -r examples/* cli/pkg/examples/embed/dist/
rm -rf runtime/pkg/examples/embed/dist || true
mkdir -p runtime/pkg/examples/embed/dist
git clone --quiet https://github.com/rilldata/rill-examples.git runtime/pkg/examples/embed/dist
rm -rf runtime/pkg/examples/embed/dist/.git

.PHONY: coverage.go
coverage.go:
Expand Down
140 changes: 0 additions & 140 deletions cli/cmd/initialize/init.go

This file was deleted.

2 changes: 0 additions & 2 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/rilldata/rill/cli/cmd/deploy"
"github.com/rilldata/rill/cli/cmd/docs"
"github.com/rilldata/rill/cli/cmd/env"
"github.com/rilldata/rill/cli/cmd/initialize"
"github.com/rilldata/rill/cli/cmd/org"
"github.com/rilldata/rill/cli/cmd/project"
"github.com/rilldata/rill/cli/cmd/runtime"
Expand Down Expand Up @@ -115,7 +114,6 @@ func runCmd(ctx context.Context, ver config.Version) error {

// Add sub-commands
rootCmd.AddCommand(start.StartCmd(cfg))
rootCmd.AddCommand(initialize.InitCmd(cfg))
rootCmd.AddCommand(admin.AdminCmd(cfg))
rootCmd.AddCommand(runtime.RuntimeCmd(cfg))
rootCmd.AddCommand(docs.DocsCmd(cfg, rootCmd))
Expand Down
74 changes: 25 additions & 49 deletions cli/cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func StartCmd(cfg *config.Config) *cobra.Command {
var strict bool
var logFormat string
var variables []string
var exampleName string

startCmd := &cobra.Command{
Use: "start [<path>]",
Expand All @@ -51,36 +50,32 @@ func StartCmd(cfg *config.Config) *cobra.Command {
return fmt.Errorf("required arg <path> missing")
}

if !cmd.Flags().Changed("example") {
currentDir, err := filepath.Abs("")
if err != nil {
return err
}
currentDir, err := filepath.Abs("")
if err != nil {
return err
}

projectPath = currentDir
homeDir, err := os.UserHomeDir()
if err != nil {
return err
}
projectPath = currentDir
homeDir, err := os.UserHomeDir()
if err != nil {
return err
}

displayPath := currentDir
defval := true
if strings.HasPrefix(currentDir, homeDir) {
displayPath = strings.Replace(currentDir, homeDir, "~", 1)
if currentDir == homeDir {
defval = false
displayPath = "~/"
}
displayPath := currentDir
defval := true
if strings.HasPrefix(currentDir, homeDir) {
displayPath = strings.Replace(currentDir, homeDir, "~", 1)
if currentDir == homeDir {
defval = false
displayPath = "~/"
}
}

msg := fmt.Sprintf("Rill will create project files in %q. Do you want to continue?", displayPath)
confirm := cmdutil.ConfirmPrompt(msg, "", defval)
if !confirm {
cmdutil.WarnPrinter("Aborted")
return nil
}
} else {
projectPath = exampleName
msg := fmt.Sprintf("Rill will create project files in %q. Do you want to continue?", displayPath)
confirm := cmdutil.ConfirmPrompt(msg, "", defval)
if !confirm {
cmdutil.WarnPrinter("Aborted")
return nil
}
}

Expand All @@ -95,31 +90,13 @@ func StartCmd(cfg *config.Config) *cobra.Command {
}
defer app.Close()

if cmd.Flags().Changed("example") {
if exampleName != "" {
fmt.Println("Visit our documentation for more examples: https://docs.rilldata.com.")
fmt.Println("")
}

err = app.InitProject(exampleName)
if app.IsProjectInit() {
err = app.Reconcile(strict)
if err != nil {
return fmt.Errorf("init project: %w", err)
return fmt.Errorf("reconcile project: %w", err)
}
}

// If not initialized, init repo with an empty project
if !app.IsProjectInit() {
err = app.InitProject("")
if err != nil {
return fmt.Errorf("init project: %w", err)
}
}

err = app.Reconcile(strict)
if err != nil {
return fmt.Errorf("reconcile project: %w", err)
}

userID := ""
if cfg.IsAuthenticated() {
userID, _ = cmdutil.FetchUserID(context.Background(), cfg)
Expand All @@ -146,7 +123,6 @@ func StartCmd(cfg *config.Config) *cobra.Command {
startCmd.Flags().BoolVar(&strict, "strict", false, "Exit if project has build errors")
startCmd.Flags().StringVar(&logFormat, "log-format", "console", "Log format (options: \"console\", \"json\")")
startCmd.Flags().StringSliceVarP(&variables, "env", "e", []string{}, "Set project variables")
startCmd.Flags().StringVar(&exampleName, "example", "default", "Name of example project")

return startCmd
}
65 changes: 0 additions & 65 deletions cli/pkg/examples/example.go

This file was deleted.

Loading

1 comment on commit c1cb889

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.