diff --git a/cmd/addRepo.go b/cmd/addRepo.go index 605884c..d1e5be6 100644 --- a/cmd/addRepo.go +++ b/cmd/addRepo.go @@ -51,6 +51,7 @@ var addRepoCmd = &cobra.Command{ return nil }, Run: func(cmd *cobra.Command, args []string) { + initConfig() PrintMsg("Fetching repository...") name := args[0] repoUrl := args[1] diff --git a/cmd/helmConcept.go b/cmd/helmConcept.go index 898c1b9..fbd3de0 100644 --- a/cmd/helmConcept.go +++ b/cmd/helmConcept.go @@ -43,6 +43,7 @@ kable helm concept --directory cert-manager cert-manager --repo jetstack --repoU return nil }, Run: func(cmd *cobra.Command, args []string) { + initConfig() PrintMsg("Creating concept from helm chart '%s'...", args[0]) if err := helm.InitHelmConcept(helm.HelmChart{Name: args[0], Version: chartVersion, Repo: helm.HelmRepo{Name: chartRepoName, URL: chartRepoURL}}, dir); err != nil { PrintError("unable to import helm chart: %s", err) diff --git a/cmd/helmImport.go b/cmd/helmImport.go index 994997d..7738834 100644 --- a/cmd/helmImport.go +++ b/cmd/helmImport.go @@ -42,6 +42,7 @@ kable helm import cert-manager --repo jetstack --repoURL https://charts.jetstack return nil }, Run: func(cmd *cobra.Command, args []string) { + initConfig() if _, err := concepts.GetConcept("."); err != nil { PrintError("current directory is not a concept directory: %s", err) } diff --git a/cmd/initConcept.go b/cmd/initConcept.go index 35401ba..2edd4c1 100644 --- a/cmd/initConcept.go +++ b/cmd/initConcept.go @@ -31,6 +31,7 @@ var initConceptCmd = &cobra.Command{ Use: "init", Short: "Initialize a concept in the current folder", Run: func(cmd *cobra.Command, args []string) { + initConfig() wd, err := os.Getwd() if err != nil { PrintError("unable to initialize concept dir: %s", err) diff --git a/cmd/listConcept.go b/cmd/listConcept.go index 3453d8c..220aa3c 100644 --- a/cmd/listConcept.go +++ b/cmd/listConcept.go @@ -25,6 +25,7 @@ var listConceptsCmd = &cobra.Command{ Use: "list", Short: "List all available concepts", Run: func(cmd *cobra.Command, args []string) { + initConfig() cis, err := concepts.ListConcepts() if err != nil { PrintError("unable to list concepts: %s", err) diff --git a/cmd/listRepo.go b/cmd/listRepo.go index d83447b..2fa060d 100644 --- a/cmd/listRepo.go +++ b/cmd/listRepo.go @@ -25,6 +25,7 @@ var listReposCmd = &cobra.Command{ Use: "list", Short: "Lists all available concept repositories", Run: func(cmd *cobra.Command, args []string) { + initConfig() repos, err := repositories.ListRepositories() if err != nil { PrintError("cannot list repositories: %s \n", err) diff --git a/cmd/removeRepo.go b/cmd/removeRepo.go index 3201bde..6f12c87 100644 --- a/cmd/removeRepo.go +++ b/cmd/removeRepo.go @@ -44,6 +44,7 @@ var removeCmd = &cobra.Command{ return nil }, Run: func(cmd *cobra.Command, args []string) { + initConfig() PrintMsg("Removing repository...") mod, err := repositories.RemoveRepository(args[0]) if err != nil { diff --git a/cmd/renderConcept.go b/cmd/renderConcept.go index 96c0e91..b611e6d 100644 --- a/cmd/renderConcept.go +++ b/cmd/renderConcept.go @@ -65,6 +65,7 @@ kable render -l . -o out/ return nil }, Run: func(cmd *cobra.Command, args []string) { + initConfig() conceptIdentifier := concepts.ConceptIdentifier(args[0]) if printOnly { diff --git a/cmd/root.go b/cmd/root.go index f864341..7229d6d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -32,7 +32,7 @@ func Execute() { func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kable/userconfig.json)") - cobra.OnInitialize(initConfig) + //cobra.OnInitialize(initConfig) bindFlags(rootCmd, viper.GetViper()) } @@ -62,7 +62,6 @@ func initConfig() { viper.SetEnvPrefix("KABLE") viper.AutomaticEnv() - } // Bind each cobra flag to its associated viper configuration (config file and environment variable) diff --git a/cmd/serve.go b/cmd/serve.go index 168cd1f..63b9c66 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -40,6 +40,7 @@ var serveCmd = &cobra.Command{ Example: `kable serve --server-address 127.0.0.1 --server-port 2020 KABLE_SERVERADDRESS=127.0.0.1 KABLE_SERVERPORT kable serve`, Run: func(cmd *cobra.Command, args []string) { + initConfig() viper.Set(repositories.StoreKey, repositories.EtcdStoreConfigMap(strings.Split(viper.GetString(etcdEndpoints), ","), viper.GetDuration(etcdTimeout)).Map()) api.StartUp(fmt.Sprintf("%s:%s", viper.Get(serverAddressKey), viper.Get(serverPortKey))) }, diff --git a/cmd/tidyRepo.go b/cmd/tidyRepo.go index d65814d..e1fb165 100644 --- a/cmd/tidyRepo.go +++ b/cmd/tidyRepo.go @@ -25,6 +25,7 @@ var tidyCmd = &cobra.Command{ Use: "tidy", Short: "Clean up removed, cached repos", Run: func(cmd *cobra.Command, args []string) { + initConfig() PrintMsg("Tidying up cached repositories...") err := repositories.TidyCache() if err != nil { diff --git a/cmd/ui.go b/cmd/ui.go index f345a71..68f71d7 100644 --- a/cmd/ui.go +++ b/cmd/ui.go @@ -36,6 +36,7 @@ var uiCmd = &cobra.Command{ Example: `kable ui --ui-address 127.0.0.1 --ui-port 2020 KABLE_UIADDRESS=127.0.0.1 KABLE_UIPORT kable ui`, Run: func(cmd *cobra.Command, args []string) { + initConfig() err := ui.StartUp(fmt.Sprintf("%s:%s", viper.Get(uiAddressKey), viper.Get(uiPortKey))) if err != nil { PrintError("error occurred while running server: %v", err) diff --git a/cmd/updateRepo.go b/cmd/updateRepo.go index 441d7b9..4835f0f 100644 --- a/cmd/updateRepo.go +++ b/cmd/updateRepo.go @@ -25,6 +25,7 @@ var updateCmd = &cobra.Command{ Use: "update", Short: "Update all the configured repositories", Run: func(cmd *cobra.Command, args []string) { + initConfig() PrintMsg("Updating repositories...") if err := repositories.UpdateRepositories(); err != nil { PrintError("unable to update repositories: %s", err)