MCPcopy
hub / github.com/keploy/keploy / ValidateFlags

Method ValidateFlags

cli/provider/cmd.go:673–1580  ·  view source on GitHub ↗
(ctx context.Context, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

671}
672
673func (c *CmdConfigurator) ValidateFlags(ctx context.Context, cmd *cobra.Command) error {
674 // The --json flag isn't registered on every subcommand (record / agent
675 // don't define it in enterprise builds), so Lookup + fallback avoids
676 // an early-return that would skip every subsequent validation step
677 // below (including the agent-mode wiring that the agent subprocess
678 // needs — without it, the agent starts up with mode="").
679 jsonOutput := false
680 if cmd.Flags().Lookup("json") != nil {
681 if v, err := cmd.Flags().GetBool("json"); err == nil {
682 jsonOutput = v
683 } else {
684 utils.LogError(c.logger, err, "failed to get the json flag")
685 }
686 }
687 c.cfg.JSONOutput = jsonOutput
688
689 // In JSON mode, redirect logs to stderr so they don't contaminate JSON on stdout
690 if c.cfg.JSONOutput {
691 logger, err := log.RedirectToStderr()
692 if err == nil {
693 *c.logger = *logger
694 }
695 }
696
697 disableAnsi, _ := (cmd.Flags().GetBool("disable-ansi"))
698 // Skip printing logo for agent command to avoid duplicate logos in native mode
699 if cmd.Name() != "agent" && !c.cfg.JSONOutput {
700 PrintLogo(os.Stdout, disableAnsi)
701 }
702 if c.cfg.Debug {
703 logger, err := log.ChangeLogLevel(zap.DebugLevel)
704 *c.logger = *logger
705 if err != nil {
706 errMsg := "failed to change log level"
707 utils.LogError(c.logger, err, errMsg)
708 return errors.New(errMsg)
709 }
710 }
711
712 if c.cfg.Record.BasePath != "" {
713 port, err := pkg.ExtractPort(c.cfg.Record.BasePath)
714 if err != nil {
715 errMsg := "failed to extract port from base URL"
716 utils.LogError(c.logger, err, errMsg)
717 return errors.New(errMsg)
718 }
719 c.cfg.Port = port
720 c.cfg.E2E = true
721 }
722
723 // Add mode to logger for agent command to differentiate agent logs from client logs
724 if cmd.Name() == "agent" {
725 logger, err := log.AddMode(cmd.Name())
726 *c.logger = *logger
727 if err != nil {
728 errMsg := "failed to add mode to logger"
729 utils.LogError(c.logger, err, errMsg)
730 return errors.New(errMsg)

Callers 1

ValidateMethod · 0.95

Implementers 1

CmdConfiguratorcli/provider/cmd.go

Calls 15

noCommandErrorMethod · 0.95
LogErrorFunction · 0.92
RedirectToStderrFunction · 0.92
ChangeLogLevelFunction · 0.92
ExtractPortFunction · 0.92
AddModeFunction · 0.92
ChangeColorEncodingFunction · 0.92
ToAbsPathFunction · 0.92
SetSelectedTestSetsFunction · 0.92
GetAbsPathFunction · 0.92

Tested by

no test coverage detected