Skip to content

Commit

Permalink
fix: remove unnecessary cmd reference
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 76b402e commit 351760e
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 76 deletions.
4 changes: 2 additions & 2 deletions cmd/cliclient/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) {
if flagx.MustGetBool(cmd, "read-from-env") {
d = driver.NewWithoutInit(
cmd.Context(),
cmd,
cmd.ErrOrStderr(),
configx.WithFlags(cmd.Flags()),
configx.SkipValidation())
if len(d.Config(cmd.Context()).DSN()) == 0 {
Expand All @@ -47,7 +47,7 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) {
}
d = driver.NewWithoutInit(
cmd.Context(),
cmd,
cmd.ErrOrStderr(),
configx.WithFlags(cmd.Flags()),
configx.SkipValidation(),
configx.WithValue(config.ViperKeyDSN, args[0]))
Expand Down
2 changes: 1 addition & 1 deletion cmd/courier/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewWatchCmd() *cobra.Command {
Use: "watch",
Short: "Starts the Ory Kratos message courier",
Run: func(cmd *cobra.Command, args []string) {
r := driver.New(cmd.Context(), cmd, configx.WithFlags(cmd.Flags()))
r := driver.New(cmd.Context(), cmd.ErrOrStderr(), configx.WithFlags(cmd.Flags()))
StartCourier(cmd.Context(), r)
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/hashers/argon2/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func configProvider(cmd *cobra.Command, flagConf *argon2Config) (*argon2Config,
conf.config, err = config.New(
context.Background(),
l,
cmd,
cmd.ErrOrStderr(),
configx.WithFlags(cmd.Flags()),
configx.SkipValidation(),
configx.WithContext(cmd.Context()),
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewServeCmd() (serveCmd *cobra.Command) {
Use: "serve",
Short: "Run the Ory Kratos server",
Run: func(cmd *cobra.Command, args []string) {
d := driver.New(cmd.Context(), cmd, configx.WithFlags(cmd.Flags()))
d := driver.New(cmd.Context(), cmd.ErrOrStderr(), configx.WithFlags(cmd.Flags()))

if d.Config(cmd.Context()).IsInsecureDevMode() {
d.Logger().Warn(`
Expand Down
17 changes: 7 additions & 10 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (

"github.com/duo-labs/webauthn/webauthn"

"github.com/spf13/cobra"

"github.com/ory/x/jsonschemax"

"github.com/ory/x/watcherx"
Expand Down Expand Up @@ -202,7 +200,7 @@ type (
l *logrusx.Logger
p *configx.Provider
identitySchema *jsonschema.Schema
cmd *cobra.Command
stdOutOrErr io.Writer
}

Provider interface {
Expand Down Expand Up @@ -256,13 +254,13 @@ func (s Schemas) FindSchemaByID(id string) (*Schema, error) {
return nil, errors.Errorf("could not find schema with id \"%s\"", id)
}

func MustNew(t *testing.T, l *logrusx.Logger, cmd *cobra.Command, opts ...configx.OptionModifier) *Config {
p, err := New(context.TODO(), l, cmd, opts...)
func MustNew(t *testing.T, l *logrusx.Logger, stdOutOrErr io.Writer, opts ...configx.OptionModifier) *Config {
p, err := New(context.TODO(), l, stdOutOrErr, opts...)
require.NoError(t, err)
return p
}

func New(ctx context.Context, l *logrusx.Logger, cmd *cobra.Command, opts ...configx.OptionModifier) (*Config, error) {
func New(ctx context.Context, l *logrusx.Logger, stdOutOrErr io.Writer, opts ...configx.OptionModifier) (*Config, error) {
var c *Config

opts = append([]configx.OptionModifier{
Expand Down Expand Up @@ -290,7 +288,7 @@ func New(ctx context.Context, l *logrusx.Logger, cmd *cobra.Command, opts ...con

l.UseConfig(p)

c = &Config{l: l, p: p, cmd: cmd}
c = &Config{l: l, p: p, stdOutOrErr: stdOutOrErr}

if !p.SkipValidation() {
if err := c.validateIdentitySchemas(); err != nil {
Expand Down Expand Up @@ -344,9 +342,8 @@ func (p *Config) validateIdentitySchemas() error {
}

func (p *Config) formatJsonErrors(schema []byte, err error) {
_, _ = fmt.Fprintln(p.cmd.ErrOrStderr(), "")

jsonschemax.FormatValidationErrorForCLI(p.cmd.ErrOrStderr(), schema, err)
_, _ = fmt.Fprintln(p.stdOutOrErr, "")
jsonschemax.FormatValidationErrorForCLI(p.stdOutOrErr, schema, err)
}

func (p *Config) Source() *configx.Provider {
Expand Down

0 comments on commit 351760e

Please sign in to comment.