Normalize retrieves the command to normalize Keploy
(ctx context.Context, logger *zap.Logger, _ *config.Config, serviceFactory ServiceFactory, cmdConfigurator CmdConfigurator)
| 16 | |
| 17 | // Normalize retrieves the command to normalize Keploy |
| 18 | func Normalize(ctx context.Context, logger *zap.Logger, _ *config.Config, serviceFactory ServiceFactory, cmdConfigurator CmdConfigurator) *cobra.Command { |
| 19 | var normalizeCmd = &cobra.Command{ |
| 20 | Use: "normalize", |
| 21 | Short: "Normalize Keploy", |
| 22 | Example: "keploy normalize --test-run testrun --tests test-set-1:test-case-1 test-case-2,test-set-2:test-case-1 test-case-2 ", |
| 23 | PreRunE: func(cmd *cobra.Command, _ []string) error { |
| 24 | return cmdConfigurator.Validate(ctx, cmd) |
| 25 | }, |
| 26 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 27 | svc, err := serviceFactory.GetService(ctx, cmd.Name()) |
| 28 | if err != nil { |
| 29 | utils.LogError(logger, err, "failed to get service", zap.String("command", cmd.Name())) |
| 30 | return nil |
| 31 | } |
| 32 | var tools toolsSvc.Service |
| 33 | var ok bool |
| 34 | if tools, ok = svc.(toolsSvc.Service); !ok { |
| 35 | utils.LogError(logger, nil, "service doesn't satisfy tools service interface") |
| 36 | return nil |
| 37 | } |
| 38 | if err := tools.Normalize(ctx); err != nil { |
| 39 | utils.LogError(logger, err, "failed to normalize test cases") |
| 40 | return nil |
| 41 | } |
| 42 | return nil |
| 43 | }, |
| 44 | } |
| 45 | if err := cmdConfigurator.AddFlags(normalizeCmd); err != nil { |
| 46 | utils.LogError(logger, err, "failed to add normalize cmd flags") |
| 47 | return nil |
| 48 | } |
| 49 | return normalizeCmd |
| 50 | } |