MCPcopy
hub / github.com/keploy/keploy / Root

Function Root

cli/root.go:14–55  ·  view source on GitHub ↗
(ctx context.Context, logger *zap.Logger, svcFactory ServiceFactory, cmdConfigurator CmdConfigurator)

Source from the content-addressed store, hash-verified

12)
13
14func Root(ctx context.Context, logger *zap.Logger, svcFactory ServiceFactory, cmdConfigurator CmdConfigurator) *cobra.Command {
15 conf := config.New()
16
17 var rootCmd = &cobra.Command{
18 Use: "keploy",
19 Short: "Keploy CLI",
20 Example: provider.RootExamples,
21 Version: utils.Version,
22 PreRun: func(cmd *cobra.Command, _ []string) {
23 disableAnsi, _ := cmd.Flags().GetBool("disable-ansi")
24 provider.PrintLogo(os.Stdout, disableAnsi)
25 },
26 }
27
28 defaultHelpFunc := rootCmd.HelpFunc()
29
30 rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
31 disableAnsi, _ := cmd.Flags().GetBool("disable-ansi")
32 provider.PrintLogo(os.Stdout, disableAnsi)
33
34 // Use the default help function instead of calling the parent's HelpFunc
35 defaultHelpFunc(cmd, args)
36 })
37
38 rootCmd.CompletionOptions.DisableDefaultCmd = true
39
40 rootCmd.SetHelpTemplate(provider.RootCustomHelpTemplate)
41
42 rootCmd.SetVersionTemplate(provider.VersionTemplate)
43
44 err := cmdConfigurator.AddFlags(rootCmd)
45 if err != nil {
46 utils.LogError(logger, err, "failed to set flags")
47 return nil
48 }
49
50 for _, cmd := range Registered {
51 c := cmd(ctx, logger, conf, svcFactory, cmdConfigurator)
52 rootCmd.AddCommand(c)
53 }
54 return rootCmd
55}

Callers 1

startFunction · 0.92

Calls 4

NewFunction · 0.92
PrintLogoFunction · 0.92
LogErrorFunction · 0.92
AddFlagsMethod · 0.65

Tested by

no test coverage detected