| 17 | } |
| 18 | |
| 19 | func Export(ctx context.Context, logger *zap.Logger, _ *config.Config, serviceFactory ServiceFactory, cmdConfigurator CmdConfigurator) *cobra.Command { |
| 20 | |
| 21 | var exportCmd = &cobra.Command{ |
| 22 | Use: "export", |
| 23 | Short: "export Keploy tests as postman collection", |
| 24 | Example: "keploy export", |
| 25 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 26 | disableAnsi, _ := (cmd.Flags().GetBool("disable-ansi")) |
| 27 | provider.PrintLogo(os.Stdout, disableAnsi) |
| 28 | return cmd.Help() |
| 29 | }, |
| 30 | } |
| 31 | var postmanCmd = &cobra.Command{ |
| 32 | Use: "postman", |
| 33 | Short: "export Keploy tests as Postman collection", |
| 34 | Example: "keploy export postman", |
| 35 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 36 | disableAnsi, _ := (cmd.Flags().GetBool("disable-ansi")) |
| 37 | provider.PrintLogo(os.Stdout, disableAnsi) |
| 38 | svc, err := serviceFactory.GetService(ctx, "export") |
| 39 | if err != nil { |
| 40 | utils.LogError(logger, err, "failed to get service", zap.String("command", cmd.Name())) |
| 41 | return nil |
| 42 | } |
| 43 | var tools toolsSvc.Service |
| 44 | var ok bool |
| 45 | if tools, ok = svc.(toolsSvc.Service); !ok { |
| 46 | utils.LogError(logger, nil, "service doesn't satisfy tools service interface") |
| 47 | return nil |
| 48 | } |
| 49 | err = tools.Export(ctx) // Assuming ExportPostmanCollection is a method in tools service |
| 50 | if err != nil { |
| 51 | utils.LogError(logger, err, "failed to export Postman collection") |
| 52 | } |
| 53 | return nil |
| 54 | }, |
| 55 | } |
| 56 | exportCmd.AddCommand(postmanCmd) |
| 57 | |
| 58 | if err := cmdConfigurator.AddFlags(exportCmd); err != nil { |
| 59 | utils.LogError(logger, err, "failed to add export cmd flags") |
| 60 | return nil |
| 61 | } |
| 62 | return exportCmd |
| 63 | } |