Skip to content

Commit

Permalink
CLI: Support specifying org in sudo project reset (#6343)
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller authored and kaspersjo committed Jan 6, 2025
1 parent e69cb48 commit 02ddb38
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions cli/cmd/sudo/project/reset.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,31 @@
package project

import (
"fmt"

"github.com/rilldata/rill/cli/pkg/cmdutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/spf13/cobra"
)

func ResetCmd(ch *cmdutil.Helper) *cobra.Command {
var project, path string
var force bool

resetCmd := &cobra.Command{
Use: "reset [<project-name>]",
Args: cobra.MaximumNArgs(1),
Short: "Re-deploy project",
Long: "Create a new deployment for the project (and tear down the current one)",
PersistentPreRunE: cmdutil.CheckChain(cmdutil.CheckAuth(ch), cmdutil.CheckOrganization(ch)),
Use: "reset <org> <project>",
Args: cobra.ExactArgs(2),
Short: "Re-deploy the project",
Long: "Create a new deployment for the project (and tear down the current one)",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
org := args[0]
project := args[1]

client, err := ch.Client()
if err != nil {
return err
}

if len(args) > 0 {
project = args[0]
}

if !cmd.Flags().Changed("project") && len(args) == 0 && ch.Interactive {
var err error
project, err = ch.InferProjectName(ctx, ch.Org, path)
if err != nil {
return fmt.Errorf("unable to infer project name (use `--project` to explicitly specify the name): %w", err)
}
}

if !force {
ch.PrintfWarn("This will create a new deployment, which means your project may be unavailable for a while as data sources are reloaded from scratch. If you just need to refresh data, use `rill project refresh`.\n")
ok, err := cmdutil.ConfirmPrompt("Do you want to continue?", "", false)
ch.PrintfWarn("The project will be unavailable for a while as data sources are reloaded from scratch. If you just need to refresh data, use `rill project refresh`.\n")
ok, err := cmdutil.ConfirmPrompt("Continue?", "", false)
if err != nil {
return err
}
Expand All @@ -49,20 +34,21 @@ func ResetCmd(ch *cmdutil.Helper) *cobra.Command {
}
}

_, err = client.RedeployProject(ctx, &adminv1.RedeployProjectRequest{Organization: ch.Org, Project: project})
_, err = client.RedeployProject(cmd.Context(), &adminv1.RedeployProjectRequest{
Organization: org,
Project: project,
})
if err != nil {
return err
}

fmt.Printf("Triggered project reset. To see status, run `rill project status --project %s`.\n", project)
ch.Printf("Triggered reset of %q.\n", project)

return nil
},
}

resetCmd.Flags().SortFlags = false
resetCmd.Flags().StringVar(&project, "project", "", "Project name")
resetCmd.Flags().StringVar(&path, "path", ".", "Project directory")
resetCmd.Flags().BoolVar(&force, "force", false, "Force reset even if project is already deployed")
return resetCmd
}

0 comments on commit 02ddb38

Please sign in to comment.