github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/config/api_server_port.go (about) 1 package config 2 3 import ( 4 "fmt" 5 "strconv" 6 7 "github.com/spf13/cobra" 8 9 "github.com/kubeshop/testkube/cmd/kubectl-testkube/config" 10 "github.com/kubeshop/testkube/pkg/ui" 11 ) 12 13 // NewConfigureAPIServerPortCmd is api server port config command 14 func NewConfigureAPIServerPortCmd() *cobra.Command { 15 cmd := &cobra.Command{ 16 Use: "api-server-port <value>", 17 Short: "Set api server port for testkube client", 18 Args: func(cmd *cobra.Command, args []string) error { 19 if len(args) < 1 { 20 return fmt.Errorf("please pass valid api server port value") 21 } 22 23 if _, err := strconv.Atoi(args[0]); err != nil { 24 return fmt.Errorf("please pass integer api server port value: %w", err) 25 } 26 27 return nil 28 }, 29 Run: func(cmd *cobra.Command, args []string) { 30 cfg, err := config.Load() 31 ui.ExitOnError("loading config file", err) 32 33 port, err := strconv.Atoi(args[0]) 34 ui.ExitOnError("converting port value", err) 35 36 cfg.APIServerPort = port 37 err = config.Save(cfg) 38 ui.ExitOnError("saving config file", err) 39 ui.Success("New api server port set to", strconv.Itoa(cfg.APIServerPort)) 40 }, 41 } 42 43 return cmd 44 }