From 77077a435f8434546a03effc63614e64868011bf Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Sun, 18 Feb 2024 18:35:44 -0500 Subject: [PATCH] cmd: deprecate root-level head and migrate These make more sense under the datastore command. This change introduces a convenience function for warning when a deprecated command is used. --- cmd/spicedb/main.go | 16 ++++++++++------ pkg/cmd/datastore.go | 4 ++++ pkg/cmd/root.go | 10 ++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cmd/spicedb/main.go b/cmd/spicedb/main.go index edca7049cd..667f1ca17b 100644 --- a/cmd/spicedb/main.go +++ b/cmd/spicedb/main.go @@ -43,11 +43,6 @@ func main() { cmd.RegisterVersionFlags(versionCmd) rootCmd.AddCommand(versionCmd) - // Add migration commands - migrateCmd := cmd.NewMigrateCommand(rootCmd.Use) - cmd.RegisterMigrateFlags(migrateCmd) - rootCmd.AddCommand(migrateCmd) - // Add datastore commands datastoreCmd, err := cmd.NewDatastoreCommand(rootCmd.Use) if err != nil { @@ -57,11 +52,20 @@ func main() { cmd.RegisterDatastoreRootFlags(datastoreCmd) rootCmd.AddCommand(datastoreCmd) - // Add head command. + // Add deprecated head command headCmd := cmd.NewHeadCommand(rootCmd.Use) cmd.RegisterHeadFlags(headCmd) + headCmd.Hidden = true + headCmd.RunE = cmd.DeprecatedRunE(headCmd.RunE, "spicedb datastore head") rootCmd.AddCommand(headCmd) + // Add deprecated migrate command + migrateCmd := cmd.NewMigrateCommand(rootCmd.Use) + migrateCmd.Hidden = true + migrateCmd.RunE = cmd.DeprecatedRunE(migrateCmd.RunE, "spicedb datastore migrate") + cmd.RegisterMigrateFlags(migrateCmd) + rootCmd.AddCommand(migrateCmd) + // Add server commands serverConfig := cmdutil.NewConfigWithOptionsAndDefaults() serveCmd := cmd.NewServeCommand(rootCmd.Use, serverConfig) diff --git a/pkg/cmd/datastore.go b/pkg/cmd/datastore.go index c8fef084fc..9682b2b373 100644 --- a/pkg/cmd/datastore.go +++ b/pkg/cmd/datastore.go @@ -43,6 +43,10 @@ func NewDatastoreCommand(programName string) (*cobra.Command, error) { } datastoreCmd.AddCommand(repairCmd) + headCmd := NewHeadCommand(programName) + RegisterHeadFlags(headCmd) + datastoreCmd.AddCommand(headCmd) + return datastoreCmd, nil } diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 26ebbfa70a..4d405a564b 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -1,10 +1,12 @@ package cmd import ( + "github.com/jzelinskie/cobrautil/v2" "github.com/jzelinskie/cobrautil/v2/cobraotel" "github.com/jzelinskie/cobrautil/v2/cobrazerolog" "github.com/spf13/cobra" + log "github.com/authzed/spicedb/internal/logging" "github.com/authzed/spicedb/pkg/cmd/server" "github.com/authzed/spicedb/pkg/cmd/termination" "github.com/authzed/spicedb/pkg/releases" @@ -19,6 +21,14 @@ func RegisterRootFlags(cmd *cobra.Command) { runtime.RegisterFlags(cmd.PersistentFlags()) } +// DeprecatedRunE wraps the RunFunc with a warning log statement. +func DeprecatedRunE(fn cobrautil.CobraRunFunc, newCmd string) cobrautil.CobraRunFunc { + return func(cmd *cobra.Command, args []string) error { + log.Warn().Str("newCommand", newCmd).Msg("use of deprecated command") + return fn(cmd, args) + } +} + func NewRootCommand(programName string) *cobra.Command { return &cobra.Command{ Use: programName,