@@ -16,7 +16,9 @@ limitations under the License.
1616package cmd
1717
1818import (
19+ "fmt"
1920 "os"
21+ "path/filepath"
2022
2123 log "github.com/sirupsen/logrus"
2224 "github.com/spf13/cobra"
@@ -35,24 +37,56 @@ var runCmd = &cobra.Command{
3537 Long : profileLongHelp (),
3638 ValidArgsFunction : profileValidArgs ,
3739 Run : func (cmd * cobra.Command , args []string ) {
38- // Set Config file based on the profile
39- viper .SetConfigFile (ProfileDir + "/" + args [0 ] + "/config.yaml" )
40+ // Look for all yaml files in the profile directory
41+ configFiles , err := filepath .Glob (filepath .Join (ProfileDir + "/" + args [0 ], "*.yaml" ))
42+ if err != nil {
43+ log .Fatal (err )
44+ }
4045
41- // Read the config file, Only displaying an error if there was a problem reading the file.
42- if err := viper .ReadInConfig (); err != nil {
43- if _ , ok := err .(viper.ConfigFileNotFoundError ); ! ok {
44- log .Fatal (err )
45- }
46+ // If no config files are found, exit with an error
47+ if len (configFiles ) == 0 {
48+ log .Fatalf ("No config files found in profile directory: %s" , ProfileDir + "/" + args [0 ])
4649 }
4750
48- // If the view flag is set, show the config
49- if view , _ := cmd .Flags ().GetBool ("view" ); view {
50- showconfigCmd . Run ( cmd , [] string {})
51- os . Exit ( 0 )
51+ // Get view flag
52+ view , err := cmd .Flags ().GetBool ("view" )
53+ if err != nil {
54+ log . Fatal ( err )
5255 }
5356
54- // Run the profile
55- startCmd .Run (cmd , []string {})
57+ // Iterate over all config files and run the profile for each one
58+ for _ , configFile := range configFiles {
59+ // Set Config file based on the profile
60+ viper .SetConfigFile (configFile )
61+
62+ // Read the config file, Only displaying an error if there was a problem reading the file.
63+ if err := viper .ReadInConfig (); err != nil {
64+ if _ , ok := err .(viper.ConfigFileNotFoundError ); ! ok {
65+ log .Fatal (err )
66+ }
67+ }
68+
69+ // If the view flag is set, show the config
70+ if view {
71+ // Crude, but it works
72+ // TODO: Create a "BeKindStack" YAML struct and use that to display the config
73+ fmt .Println ("---" )
74+ showconfigCmd .Run (cmd , []string {})
75+ } else {
76+ // I assume you want to "Run the profile"
77+ if ! view {
78+ log .Info ("Running profile: " , args [0 ], " with config file: " , filepath .Base (configFile ))
79+ startCmd .Run (cmd , []string {})
80+ }
81+
82+ }
83+
84+ // Clear viper config for next iteration
85+ viper .Reset ()
86+
87+ // Reset global variables from start.go to prevent state leakage between iterations
88+ ResetGlobalVars ()
89+ }
5690 },
5791}
5892
@@ -93,7 +127,9 @@ func profileLongHelp() string {
93127 return `You can use "run" to run the specified profile. Profiles needs to be
94128stored in the ~/.bekind/profiles/{{name}} directory.
95129
96- The profile directory should contain a config.yaml file. For example:
130+ The profile directory should contain a config file in YAML format. For example:
131+
132+ ~/.bekind/profiles/{{name}}/config.yaml
97133
98- ~/.bekind/profiles/{{name}}/config.yaml `
134+ NOTE: You can have multiple YAML configurations in the same profile directory. `
99135}
0 commit comments