github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/watch.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  
     6  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
     7  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator"
     8  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/tests"
     9  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testsuites"
    10  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows"
    11  	"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
    12  	"github.com/kubeshop/testkube/pkg/ui"
    13  )
    14  
    15  func NewWatchCmd() *cobra.Command {
    16  	cmd := &cobra.Command{
    17  		Use:         "watch <resourceName>",
    18  		Aliases:     []string{"r", "start"},
    19  		Short:       "Watch tests or test suites",
    20  		Annotations: map[string]string{cmdGroupAnnotation: cmdGroupCommands},
    21  		Run: func(cmd *cobra.Command, args []string) {
    22  			err := cmd.Help()
    23  			ui.PrintOnError("Displaying help", err)
    24  		},
    25  		PersistentPreRun: func(cmd *cobra.Command, args []string) {
    26  			cfg, err := config.Load()
    27  			ui.ExitOnError("loading config", err)
    28  			common.UiContextHeader(cmd, cfg)
    29  
    30  			validator.PersistentPreRunVersionCheck(cmd, common.Version)
    31  		}}
    32  
    33  	cmd.AddCommand(tests.NewWatchExecutionCmd())
    34  	cmd.AddCommand(testsuites.NewWatchTestSuiteExecutionCmd())
    35  	cmd.AddCommand(testworkflows.NewWatchTestWorkflowExecutionCmd())
    36  
    37  	return cmd
    38  }