Skip to content

Commit

Permalink
feat: allow plugins to be specified in CLI config.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Apr 15, 2024
1 parent 98129f2 commit 9f96db0
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"gatehill.io/imposter/fileutil"
"gatehill.io/imposter/plugin"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -87,10 +88,7 @@ If CONFIG_DIR is not specified, the current working directory is used.`,

// only ensure (and potentially fetch) default plugins if not a sealed distro
if upFlags.ensurePlugins && lib.ShouldEnsurePlugins() {
_, err := plugin.EnsureDefaultPlugins(version)
if err != nil {
logger.Fatal(err)
}
ensurePlugins(version)
}
}

Expand All @@ -110,18 +108,6 @@ If CONFIG_DIR is not specified, the current working directory is used.`,
},
}

func injectExplicitEnvironment() {
for _, env := range upFlags.environment {
envParts := strings.Split(env, "=")
if len(envParts) > 1 {
_ = os.Setenv(envParts[0], envParts[1])
}
}
if upFlags.recursiveConfigScan {
_ = os.Setenv("IMPOSTER_CONFIG_SCAN_RECURSIVE", "true")
}
}

func init() {
upCmd.Flags().StringVarP(&upFlags.engineType, "engine-type", "t", "", "Imposter engine type (valid: docker,jvm - default \"docker\")")
upCmd.Flags().StringVarP(&upFlags.engineVersion, "version", "v", "", "Imposter engine version (default \"latest\")")
Expand All @@ -140,6 +126,34 @@ func init() {
rootCmd.AddCommand(upCmd)
}

func injectExplicitEnvironment() {
for _, env := range upFlags.environment {
envParts := strings.Split(env, "=")
if len(envParts) > 1 {
_ = os.Setenv(envParts[0], envParts[1])
}
}
if upFlags.recursiveConfigScan {
_ = os.Setenv("IMPOSTER_CONFIG_SCAN_RECURSIVE", "true")
}
}

func ensurePlugins(version string) {
_, err := plugin.EnsureDefaultPlugins(version)
if err != nil {
logger.Fatal(err)
}

localCliConfigPlugins := viper.GetStringSlice("plugins")
if len(localCliConfigPlugins) > 0 {
logger.Tracef("picked up plugins from CLI config: %v", localCliConfigPlugins)
_, err := plugin.EnsurePlugins(localCliConfigPlugins, version, false)
if err != nil {
logger.Fatal(err)
}
}
}

func start(lib *engine.EngineLibrary, startOptions engine.StartOptions, configDir string, restartOnChange bool) {
provider := (*lib).GetProvider(startOptions.Version)
mockEngine := provider.Build(configDir, startOptions)
Expand Down

0 comments on commit 9f96db0

Please sign in to comment.