| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package cmd
- import (
- "io/ioutil"
- "os"
- "path/filepath"
- "github.com/fatih/color"
- "github.com/spf13/cobra"
- "github.com/spf13/viper"
- "k8s.io/client-go/util/homedir"
- )
- // rootCmd represents the base command when called without any subcommands
- var rootCmd = &cobra.Command{
- Use: "porter",
- Short: "Porter is a dashboard for managing Kubernetes clusters.",
- 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`,
- }
- var home = homedir.HomeDir()
- // Execute adds all child commands to the root command and sets flags appropriately.
- // This is called by main.main(). It only needs to happen once to the rootCmd.
- func Execute() {
- viper.SetConfigName("porter")
- viper.SetConfigType("yaml")
- viper.AddConfigPath(filepath.Join(home, ".porter"))
- err := viper.ReadInConfig()
- if err != nil {
- if _, ok := err.(viper.ConfigFileNotFoundError); ok {
- // create blank config file
- err := ioutil.WriteFile(filepath.Join(home, ".porter", "porter.yaml"), []byte{}, 0644)
- if err != nil {
- color.New(color.FgRed).Printf("%v\n", err)
- os.Exit(1)
- }
- } else {
- // Config file was found but another error was produced
- color.New(color.FgRed).Printf("%v\n", err)
- os.Exit(1)
- }
- }
- if err := rootCmd.Execute(); err != nil {
- color.New(color.FgRed).Println(err)
- os.Exit(1)
- }
- }
|