MCPcopy
hub / github.com/vektra/mockery / run

Function run

internal/cmd/migrate.go:130–227  ·  view source on GitHub ↗
(ctx context.Context, confPathStr string, v3ConfPath string)

Source from the content-addressed store, hash-verified

128}
129
130func run(ctx context.Context, confPathStr string, v3ConfPath string) error {
131 var confPath string
132 var err error
133
134 log := zerolog.Ctx(ctx)
135 if confPathStr == "" {
136 confPath, err = internalConfig.FindConfig()
137 if err != nil {
138 return fmt.Errorf("finding config: %w", err)
139 }
140 } else {
141 confPath = confPathStr
142 }
143 log.UpdateContext(func(c zerolog.Context) zerolog.Context {
144 return c.Str("config", confPath)
145 })
146 log.Info().Msg("using config")
147
148 var v2 V2RootConfig
149 f, err := os.Open(confPath)
150 if err != nil {
151 return fmt.Errorf("opening config file: %w", err)
152 }
153 defer f.Close()
154 decoder := yaml.NewDecoder(f)
155 decoder.KnownFields(true)
156 if err := decoder.Decode(&v2); err != nil {
157 log.Error().Msg("v2 config could not be decoded. Are you sure this is a v2 config file?")
158 return fmt.Errorf("decoding v2 config: %w", err)
159 }
160
161 var v3 config.RootConfig
162 var v3Config *config.Config = &config.Config{}
163 v3Config.TemplateData = map[string]any{}
164 // unroll-variadic is defaulted to true in v2, so we should set this as
165 // the top-level default (unless of course it has been explicitly set
166 // at the top-level v2 config)
167 v3Config.TemplateData["unroll-variadic"] = addr(true)
168
169 tbl := newTableWriter(ctx)
170
171 migrateConfig(ctx, tbl, &v2.V2Config, &v3Config)
172 v3Config.Template = addr("testify")
173 v3.Config = *v3Config
174
175 for pkgName, pkgConfig := range v2.Packages {
176 pkgLog := log.With().Str("pkg-name", pkgName).Logger()
177 pkgCtx := pkgLog.WithContext(ctx)
178
179 v3PkgConfig := &config.PackageConfig{}
180 if v3.Packages == nil {
181 v3.Packages = map[string]*config.PackageConfig{}
182 }
183 v3.Packages[pkgName] = v3PkgConfig
184 migrateConfig(pkgCtx, tbl, pkgConfig.Config, &v3PkgConfig.Config)
185
186 for interfaceName, interfaceConfig := range pkgConfig.Interfaces {
187 ifaceLog := pkgLog.With().Str("interface-name", interfaceName).Logger()

Callers 15

RunMethod · 0.85
RunMethod · 0.85
TestMigrateFunction · 0.85
RunMethod · 0.85
NewMigrateCmdFunction · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85

Calls 7

newTableWriterFunction · 0.85
migrateConfigFunction · 0.85
RenderMethod · 0.80
addrFunction · 0.70
CreateMethod · 0.65
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by 15

RunMethod · 0.68
RunMethod · 0.68
TestMigrateFunction · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68
RunMethod · 0.68