Skip to content

Commit

Permalink
Merge pull request #2400 from mahendrabagul/pass-on-devspace-vars-to-…
Browse files Browse the repository at this point in the history
…plugin-env

Pass on devspace vars to plugin env
  • Loading branch information
FabianKramm authored Nov 16, 2022
2 parents a644a99 + 8c65e47 commit c5aa51b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ Additional run commands:
rootCmd.AddCommand(NewPurgeCmd(f, globalFlags, rawConfig))

// Add plugin commands
if rawConfig != nil && rawConfig.OriginalRawConfig != nil {
plugin.AddDevspaceVarsToPluginEnv(rawConfig.OriginalRawConfig["vars"])
}
plugin.AddPluginCommands(rootCmd, plugins, "")
variable.AddPredefinedVars(plugins)
return rootCmd
Expand Down
23 changes: 22 additions & 1 deletion pkg/devspace/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ghodss/yaml"
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
"github.com/loft-sh/devspace/pkg/util/log"
"sync"

"io"
"os"
Expand All @@ -34,6 +35,9 @@ func init() {
}
}

var devspaceVars = map[string]string{}
var devspaceVarsOnce sync.Once

type NewestVersionError struct {
version string
}
Expand Down Expand Up @@ -355,6 +359,23 @@ func Decode(encoded string) ([]byte, error) {
return encoding.DecodeString(encoded)
}

func AddDevspaceVarsToPluginEnv(vars interface{}) {
devspaceVarsOnce.Do(func() {
if vars != nil {
devspaceVar, isMapStringInterface := vars.(map[string]interface{})
if isMapStringInterface {
for key, value := range devspaceVar {
// only map[string]string will be processed, map[string]Variable will be skipped
vString, isString := value.(string)
if isString {
devspaceVars[key] = vString
}
}
}
}
})
}

func AddPluginCommands(base *cobra.Command, plugins []Metadata, subCommand string) {
for _, plugin := range plugins {
pluginFolder := plugin.PluginFolder
Expand All @@ -373,7 +394,7 @@ func AddPluginCommands(base *cobra.Command, plugins []Metadata, subCommand strin
newArgs := []string{}
newArgs = append(newArgs, md.BaseArgs...)
newArgs = append(newArgs, args...)
return CallPluginExecutable(filepath.Join(pluginFolder, PluginBinary), newArgs, nil, os.Stdout)
return CallPluginExecutable(filepath.Join(pluginFolder, PluginBinary), newArgs, devspaceVars, os.Stdout)
},
// This passes all the flags to the subcommand.
DisableFlagParsing: true,
Expand Down

0 comments on commit c5aa51b

Please sign in to comment.