Skip to content

Commit

Permalink
cmd: deprecate root-level head and migrate
Browse files Browse the repository at this point in the history
These make more sense under the datastore command.

This change introduces a convenience function for
warning when a deprecated command is used.
  • Loading branch information
jzelinskie committed Feb 18, 2024
1 parent a32213b commit 77077a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/spicedb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand Down

0 comments on commit 77077a4

Please sign in to comment.