From 46f909678764863df4faa9f87a63bb4a461a96a1 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 13 Apr 2023 09:25:51 +0800 Subject: [PATCH] refactor: set default environment variables format in plugin - Add `INPUT_ENVS_FORMAT` to the list of environment variables in `main.go` - Define `envsFormat` variable in `plugin.go` - Add default value for `Config.EnvsFormat` in `plugin.go` `Exec()` function Signed-off-by: Bo-Yi Wu --- main.go | 4 ++-- plugin.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 4680f0b..072d323 100644 --- a/main.go +++ b/main.go @@ -199,8 +199,8 @@ func main() { &cli.StringFlag{ Name: "envs.format", Usage: "", - EnvVars: []string{"PLUGIN_ENVS_FORMAT"}, - Value: "export {NAME}={VALUE}", + EnvVars: []string{"PLUGIN_ENVS_FORMAT", "INPUT_ENVS_FORMAT"}, + Value: envsFormat, }, } diff --git a/plugin.go b/plugin.go index 6ea1654..14d619f 100644 --- a/plugin.go +++ b/plugin.go @@ -17,6 +17,7 @@ var ( errMissingHost = errors.New("Error: missing server host") errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") errCommandTimeOut = errors.New("Error: command timeout") + envsFormat = "export {NAME}={VALUE}" ) type ( @@ -179,6 +180,10 @@ func (p Plugin) Exec() error { return errMissingPasswordOrKey } + if p.Config.EnvsFormat == "" { + p.Config.EnvsFormat = envsFormat + } + wg := sync.WaitGroup{} wg.Add(len(p.Config.Host)) errChannel := make(chan error)