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

CLI: Support specifying org in sudo project reset #6343

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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
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
}
Loading