root.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "k8s.io/client-go/util/homedir"
  8. )
  9. // rootCmd represents the base command when called without any subcommands
  10. var rootCmd = &cobra.Command{
  11. Use: "porter",
  12. Short: "Porter is a dashboard for managing Kubernetes clusters.",
  13. 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`,
  14. }
  15. var home = homedir.HomeDir()
  16. // Execute adds all child commands to the root command and sets flags appropriately.
  17. // This is called by main.main(). It only needs to happen once to the rootCmd.
  18. func Execute() {
  19. Setup()
  20. rootCmd.PersistentFlags().AddFlagSet(defaultFlagSet)
  21. if err := rootCmd.Execute(); err != nil {
  22. color.New(color.FgRed).Println(err)
  23. os.Exit(1)
  24. }
  25. }
  26. func Setup() {
  27. InitAndLoadConfig()
  28. }
  29. func GetAPIClient(config *CLIConfig) *api.Client {
  30. if token := config.Token; token != "" {
  31. return api.NewClientWithToken(config.Host+"/api", token)
  32. }
  33. return api.NewClient(config.Host+"/api", "cookie.json")
  34. }