@@ -37,13 +37,20 @@ type module struct {
3737 Path string `yaml:"path"`
3838}
3939
40+ type cfgFileContents struct {
41+ VendorDirFromFile string `yaml:"vendor_dir"`
42+ Modules map [string ]module `yaml:",inline"`
43+ }
44+
4045var cfgFile string
4146
4247// VendorDir is the directory to download modules to
4348var VendorDir string
4449
50+ const defaultVendorDir = "vendor/modules"
51+
4552// Config holds our module information
46- var Config map [ string ] module
53+ var Config cfgFileContents
4754
4855// rootCmd represents the base command when called without any subcommands
4956var rootCmd = & cobra.Command {
@@ -62,12 +69,13 @@ func Execute() {
6269
6370func init () {
6471 // Exclude certain commands from initConfig
72+ rootCmd .PersistentFlags ().StringVarP (& cfgFile , "file" , "f" , "Terrafile" , "config file" )
73+ rootCmd .PersistentFlags ().StringVarP (& VendorDir , "directory" , "d" , defaultVendorDir , "module directory" )
74+
6575 commandRe := regexp .MustCompile (`(version|help)` )
6676 if (len (os .Args ) > 1 ) && ! commandRe .MatchString (os .Args [1 ]) {
6777 cobra .OnInitialize (initConfig )
6878 }
69- rootCmd .PersistentFlags ().StringVarP (& cfgFile , "file" , "f" , "Terrafile" , "config file" )
70- rootCmd .PersistentFlags ().StringVarP (& VendorDir , "directory" , "d" , "vendor/modules" , "module directory" )
7179}
7280
7381// initConfig reads in config file and ENV variables if set.
@@ -77,4 +85,7 @@ func initConfig() {
7785
7886 err = yaml .Unmarshal (yamlFile , & Config )
7987 xt .CheckIfError (cfgFile , err )
88+ if (VendorDir == defaultVendorDir ) && (Config .VendorDirFromFile != "" ) {
89+ VendorDir = Config .VendorDirFromFile
90+ }
8091}
0 commit comments