Skip to content

Commit

Permalink
FEAT: toscactl can read config from /etc/tosca configfile renamed fro…
Browse files Browse the repository at this point in the history
…m tosca.yml to config.yml
  • Loading branch information
segator committed Jun 17, 2021
1 parent b8b70e2 commit 758a0bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions client/src/go/toscactl/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"toscactl/entity"

)
Expand All @@ -17,7 +18,7 @@ import (
var (
cfgFile string
Verbose bool
appConfig *entity.ApplicationConfig
appConfig = &entity.ApplicationConfig{}
RootCmd = &cobra.Command{
Use: "toscactl",
Long: `This application Allow you to manage Tosca remotely`,
Expand Down Expand Up @@ -49,7 +50,7 @@ func initConfig() {
log.Fatal(err)
}

viper.SetConfigName("tosca") // name of config file (without extension)
viper.SetConfigName("config") // name of config file (without extension)
if cfgFile != "" { // enable ability to specify config file via flag
log.Debug("cfgFile: ", cfgFile)
viper.SetConfigFile(cfgFile)
Expand All @@ -60,17 +61,23 @@ func initConfig() {
}

viper.AddConfigPath(dir)
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME")
if runtime.GOOS != "windows" {
viper.AddConfigPath("/etc/tosca")
}else{
viper.AddConfigPath("C:\\Program Files\\Tricentis\\Tosca\\")
}
viper.AddConfigPath("$HOME/.tosca")
viper.AutomaticEnv() // read in environment variables that match
viper.SetEnvPrefix("tosca")
viper.AddConfigPath(".")
viper.BindPFlags(RootCmd.PersistentFlags())


// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
log.Infof("Using config file: %s", viper.ConfigFileUsed())
}
appConfig.Initialize()
if err:=viper.Unmarshal(&appConfig); err!=nil{
log.Errorf("Error when unmarshalling configuration %v",err)
os.Exit(1)
Expand Down
4 changes: 4 additions & 0 deletions client/src/go/toscactl/entity/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type ApplicationConfig struct {
TestTimeout time.Duration
}

func (a *ApplicationConfig) Initialize() {
a.TestTimeout = 30*time.Minute
}


func (i *StringArray) String() string {
return ""
Expand Down

0 comments on commit 758a0bd

Please sign in to comment.