Skip to content

Commit

Permalink
Merge pull request #2023 from authzed/2022-reorganize-flags-into-flag…
Browse files Browse the repository at this point in the history
…sets

Reorganize serve flags into flagsets
  • Loading branch information
tstirrat15 authored Aug 27, 2024
2 parents a137834 + 06f52bf commit fd2978a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 88 deletions.
5 changes: 2 additions & 3 deletions pkg/cmd/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/authzed/spicedb/internal/datastore/crdb"
Expand Down Expand Up @@ -160,8 +159,8 @@ type Config struct {
}

// RegisterDatastoreFlags adds datastore flags to a cobra command.
func RegisterDatastoreFlags(cmd *cobra.Command, opts *Config) error {
return RegisterDatastoreFlagsWithPrefix(cmd.Flags(), "", opts)
func RegisterDatastoreFlags(flagset *pflag.FlagSet, opts *Config) error {
return RegisterDatastoreFlagsWithPrefix(flagset, "", opts)
}

// RegisterDatastoreFlagsWithPrefix adds datastore flags to a cobra command, with each flag prefixed with the provided
Expand Down
7 changes: 7 additions & 0 deletions pkg/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/fatih/color"
"github.com/jzelinskie/cobrautil/v2"
"github.com/jzelinskie/cobrautil/v2/cobraotel"
"github.com/spf13/cobra"

crdbmigrations "github.com/authzed/spicedb/internal/datastore/crdb/migrations"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/authzed/spicedb/pkg/cmd/termination"
"github.com/authzed/spicedb/pkg/datastore"
"github.com/authzed/spicedb/pkg/migrate"
"github.com/authzed/spicedb/pkg/runtime"
)

func RegisterMigrateFlags(cmd *cobra.Command) {
Expand All @@ -29,6 +31,11 @@ func RegisterMigrateFlags(cmd *cobra.Command) {
cmd.Flags().String("datastore-mysql-table-prefix", "", "prefix to add to the name of all mysql database tables")
cmd.Flags().Uint64("migration-backfill-batch-size", 1000, "number of items to migrate per iteration of a datastore backfill")
cmd.Flags().Duration("migration-timeout", 1*time.Hour, "defines a timeout for the execution of the migration, set to 1 hour by default")

otel := cobraotel.New("spicedb")
otel.RegisterFlags(cmd.Flags())
termination.RegisterFlags(cmd.Flags())
runtime.RegisterFlags(cmd.Flags())
}

func NewMigrateCommand(programName string) *cobra.Command {
Expand Down
11 changes: 0 additions & 11 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import (
"fmt"

"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"
"github.com/authzed/spicedb/pkg/runtime"
)

func RegisterRootFlags(cmd *cobra.Command) error {
Expand All @@ -22,15 +19,7 @@ func RegisterRootFlags(cmd *cobra.Command) error {
return fmt.Errorf("failed to register zerolog flag completion: %w", err)
}

ot := cobraotel.New(cmd.Use)
ot.RegisterFlags(cmd.PersistentFlags())
if err := ot.RegisterFlagCompletion(cmd); err != nil {
return fmt.Errorf("failed to register otel flag completion: %w", err)
}

releases.RegisterFlags(cmd.PersistentFlags())
termination.RegisterFlags(cmd.PersistentFlags())
runtime.RegisterFlags(cmd.PersistentFlags())

return nil
}
Expand Down
Loading

0 comments on commit fd2978a

Please sign in to comment.