2
0

connect.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package cmd
  2. import (
  3. "os"
  4. "github.com/porter-dev/porter/cli/cmd/api"
  5. "github.com/porter-dev/porter/cli/cmd/connect"
  6. "github.com/spf13/cobra"
  7. )
  8. var (
  9. kubeconfigPath string
  10. print *bool
  11. contexts *[]string
  12. )
  13. var connectCmd = &cobra.Command{
  14. Use: "connect",
  15. Short: "Commands that connect to external clusters and providers",
  16. }
  17. var connectKubeconfigCmd = &cobra.Command{
  18. Use: "kubeconfig",
  19. Short: "Uses the local kubeconfig to connect to a cluster",
  20. Run: func(cmd *cobra.Command, args []string) {
  21. err := checkLoginAndRun(args, runConnect)
  22. if err != nil {
  23. os.Exit(1)
  24. }
  25. },
  26. }
  27. func init() {
  28. rootCmd.AddCommand(connectCmd)
  29. connectCmd.AddCommand(connectKubeconfigCmd)
  30. connectCmd.PersistentFlags().StringVar(
  31. &host,
  32. "host",
  33. getHost(),
  34. "host url of Porter instance",
  35. )
  36. projectID = *connectCmd.PersistentFlags().UintP(
  37. "project-id",
  38. "p",
  39. getProjectID(),
  40. "project id to use",
  41. )
  42. connectKubeconfigCmd.PersistentFlags().StringVarP(
  43. &kubeconfigPath,
  44. "kubeconfig",
  45. "k",
  46. "",
  47. "path to kubeconfig",
  48. )
  49. contexts = connectKubeconfigCmd.PersistentFlags().StringArray(
  50. "contexts",
  51. nil,
  52. "the list of contexts to connect (defaults to the current context)",
  53. )
  54. }
  55. func runConnect(_ *api.AuthCheckResponse, client *api.Client, _ []string) error {
  56. return connect.Kubeconfig(
  57. client,
  58. kubeconfigPath,
  59. *contexts,
  60. getProjectID(),
  61. )
  62. }