Skip to content

Commit

Permalink
update: set custom factory based on config, add context flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisvisco committed Dec 12, 2024
1 parent 007e366 commit c3887d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 5 additions & 6 deletions pkg/amigo/amigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ type Amigo struct {
CustomSchemaFactory schema.Factory[schema.Schema]
}

type OptionFn func(a *Amigo)
type OptionFn func(*Amigo)

// WithCustomSchemaFactory allows to set a custom schema factory
// A schema factory is a function that returns a schema : func(ctx *MigratorContext, tx DB, db DB) T
// This is used for custom drivers implementation
func WithCustomSchemaFactory(factory schema.Factory[schema.Schema]) OptionFn {
// WithCustomSchemaFactory returns an option function that sets a custom schema factory
// based on the config
func WithCustomSchemaFactory(factoryFn func(cfg amigoconfig.Config) schema.Factory[schema.Schema]) OptionFn {
return func(a *Amigo) {
a.CustomSchemaFactory = factory
a.CustomSchemaFactory = factoryFn(*a.Config)
}
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/amigoconfig/cli_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,20 @@ func (c *Config) OverrideWithYamlConfig(yaml *YamlConfig) {
if yaml.ShellPath != "" {
c.RootConfig.ShellPath = yaml.ShellPath
}

if yaml.Debug {
c.RootConfig.Debug = yaml.Debug
}

if yaml.ShowSQL {
c.RootConfig.ShowSQL = yaml.ShowSQL
}

if yaml.ShowSQLSyntaxHighlighting {
c.RootConfig.ShowSQLSyntaxHighlighting = yaml.ShowSQLSyntaxHighlighting
}
if yaml.CurrentContext != "" {

if yaml.CurrentContext != "" && c.RootConfig.CurrentContext == "" {
c.RootConfig.CurrentContext = yaml.CurrentContext
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/entrypoint/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func init() {

rootCmd.PersistentFlags().BoolVar(&config.Debug, "debug", false, "Print debug information")

initConfig()
rootCmd.PersistentFlags().StringVarP(&config.RootConfig.CurrentContext, "context", "c", "", "Context to use")

initConfig(cfg)

Check failure on line 107 in pkg/entrypoint/root.go

View workflow job for this annotation

GitHub Actions / test

undefined: cfg

Check failure on line 107 in pkg/entrypoint/root.go

View workflow job for this annotation

GitHub Actions / test

too many arguments in call to initConfig
}

func initConfig() {
Expand Down

0 comments on commit c3887d6

Please sign in to comment.