Skip to content

Commit

Permalink
instead of config init on every command, explicitly call it from comm…
Browse files Browse the repository at this point in the history
…ands that require config
  • Loading branch information
redradrat committed Nov 6, 2021
1 parent d48e506 commit 7dc5e4b
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/addRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions cmd/helmConcept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/helmImport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/initConcept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/listConcept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/listRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/removeRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/renderConcept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
},
Expand Down
1 change: 1 addition & 0 deletions cmd/tidyRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/updateRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7dc5e4b

Please sign in to comment.