Shim bare numbers into duration strings [#39]

Helm2's --timeout took a number of seconds, rather than the
ParseDuration-compatible string that helm3 uses. For backward-
compatibility, update a bare number into a duration string.
This commit is contained in:
Erin Call
2019-12-27 16:18:10 -08:00
parent 3b78f01b45
commit d5a59590a1
3 changed files with 15 additions and 0 deletions

View File

@@ -4,8 +4,11 @@ import (
"fmt"
"github.com/kelseyhightower/envconfig"
"io"
"regexp"
)
var justNumbers = regexp.MustCompile(`^\d+$`)
// The Config struct captures the `settings` and `environment` blocks in the application's drone
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
// config key, prefixed with `PLUGIN_`. Config from the `environment` block is uppercased, but does
@@ -62,6 +65,10 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
}
}
if justNumbers.MatchString(cfg.Timeout) {
cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout)
}
if cfg.Debug && cfg.Stderr != nil {
cfg.logDebug()
}