root.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cmd
  2. import (
  3. "os"
  4. "github.com/fatih/color"
  5. "github.com/porter-dev/porter/cli/cmd/api"
  6. "github.com/spf13/cobra"
  7. "github.com/spf13/viper"
  8. "k8s.io/client-go/util/homedir"
  9. )
  10. // rootCmd represents the base command when called without any subcommands
  11. var rootCmd = &cobra.Command{
  12. Use: "porter",
  13. Short: "Porter is a dashboard for managing Kubernetes clusters.",
  14. Long: `Porter is a tool for creating, versioning, and updating Kubernetes deployments using a visual dashboard. For more information, visit github.com/porter-dev/porter`,
  15. }
  16. var home = homedir.HomeDir()
  17. // Execute adds all child commands to the root command and sets flags appropriately.
  18. // This is called by main.main(). It only needs to happen once to the rootCmd.
  19. func Execute() {
  20. Setup()
  21. rootCmd.PersistentFlags().AddFlagSet(defaultFlagSet)
  22. if err := rootCmd.Execute(); err != nil {
  23. color.New(color.FgRed).Println(err)
  24. os.Exit(1)
  25. }
  26. }
  27. func Setup() {
  28. InitAndLoadConfig()
  29. }
  30. func GetAPIClient() *api.Client {
  31. if token := viper.GetString("token"); token != "" {
  32. return api.NewClientWithToken(config.Host+"/api", token)
  33. }
  34. return api.NewClient(config.Host+"/api", "cookie.json")
  35. }