Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix #39: support APP_NAME and name in app.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Aug 16, 2020
1 parent 2df4eac commit 7dbb327
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ func New() *cobra.Command {
cfg.SetConfigType("dotenv")
err := cfg.ReadInConfig()
if err == nil {
if !cfg.InConfig("graphite_metrics") && cfg.InConfig("app_name") {
cfg.Set("graphite_metrics", "apps.services."+cfg.GetString("app_name"))
}
return viper.MergeConfigMap(cfg.AllSettings())
}

if os.IsNotExist(err) {
cfg.SetConfigFile("app.toml")
cfg.SetConfigType("toml")
if err, sub := cfg.ReadInConfig(), cfg.Sub("envs.local.env_vars"); err == nil && sub != nil {
if !sub.InConfig("graphite_metrics") && cfg.InConfig("name") {
sub.Set("graphite_metrics", "apps.services."+cfg.GetString("name"))
}
return viper.MergeConfigMap(sub.AllSettings())
}
err = nil
Expand Down Expand Up @@ -108,6 +114,10 @@ func New() *cobra.Command {
viper.RegisterAlias("metrics", "graphite_metrics")
return viper.BindEnv("metrics", "GRAPHITE_METRICS")
},
func() error {
viper.RegisterAlias("name", "app_name")
return viper.BindEnv("name", "APP_NAME")
},
)

command.AddCommand(
Expand Down

0 comments on commit 7dbb327

Please sign in to comment.