-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support config push command (#2875)
- Loading branch information
1 parent
3257ea3
commit 3550893
Showing
3 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
"github.com/supabase/cli/internal/config/push" | ||
"github.com/supabase/cli/internal/utils/flags" | ||
) | ||
|
||
var ( | ||
configCmd = &cobra.Command{ | ||
GroupID: groupManagementAPI, | ||
Use: "config", | ||
Short: "Manage Supabase project configurations", | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) | ||
cmd.SetContext(ctx) | ||
return cmd.Root().PersistentPreRunE(cmd, args) | ||
}, | ||
} | ||
|
||
configPushCmd = &cobra.Command{ | ||
Use: "push", | ||
Short: "Pushes local config.toml to the linked project", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return push.Run(cmd.Context(), flags.ProjectRef, afero.NewOsFs()) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
configCmd.PersistentFlags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") | ||
configCmd.AddCommand(configPushCmd) | ||
rootCmd.AddCommand(configCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package push | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/supabase/cli/internal/utils" | ||
"github.com/supabase/cli/pkg/config" | ||
) | ||
|
||
func Run(ctx context.Context, ref string, fsys afero.Fs) error { | ||
if err := utils.LoadConfigFS(fsys); err != nil { | ||
return err | ||
} | ||
client := config.NewConfigUpdater(*utils.GetSupabase()) | ||
fmt.Fprintln(os.Stderr, "Pushing config to project:", ref) | ||
remote, _ := utils.Config.GetRemoteByProjectRef(ref) | ||
console := utils.NewConsole() | ||
keep := func(name string) bool { | ||
title := fmt.Sprintf("Do you want to push %s config to remote?", name) | ||
shouldPush, err := console.PromptYesNo(ctx, title, true) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
return shouldPush | ||
} | ||
return client.UpdateRemoteConfig(ctx, remote, keep) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters