Rough draft of aliased settings [#66]
This commit is contained in:
parent
7cfe20db1f
commit
04de280821
|
@ -65,6 +65,29 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var aliases settingAliases
|
||||
if err := envconfig.Process("plugin", &aliases); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if aliases.Command != nil {
|
||||
cfg.Command = *aliases.Command
|
||||
}
|
||||
if aliases.AddRepos != nil {
|
||||
cfg.AddRepos = *aliases.AddRepos
|
||||
}
|
||||
if aliases.APIServer != nil {
|
||||
cfg.APIServer = *aliases.APIServer
|
||||
}
|
||||
if aliases.ServiceAccount != nil {
|
||||
cfg.ServiceAccount = *aliases.ServiceAccount
|
||||
}
|
||||
if aliases.Wait != nil {
|
||||
cfg.Wait = *aliases.Wait
|
||||
}
|
||||
if aliases.Force != nil {
|
||||
cfg.Force = *aliases.Force
|
||||
}
|
||||
|
||||
if justNumbers.MatchString(cfg.Timeout) {
|
||||
cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout)
|
||||
}
|
||||
|
@ -94,3 +117,12 @@ func (cfg *Config) deprecationWarn() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
type settingAliases struct {
|
||||
Command *string `envconfig:"mode"`
|
||||
AddRepos *[]string `envconfig:"add_repos"`
|
||||
APIServer *string `envconfig:"kubernetes_api_server"`
|
||||
ServiceAccount *string `envconfig:"kubernetes_service_account"`
|
||||
Wait *bool `envconfig:"wait_for_upgrade"`
|
||||
Force *bool `envconfig:"force_upgrade"`
|
||||
}
|
||||
|
|
|
@ -70,6 +70,35 @@ func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
|||
suite.Equal("42s", cfg.Timeout)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithAliases() {
|
||||
for _, varname := range []string{
|
||||
"HELM_COMMAND",
|
||||
"HELM_REPOS",
|
||||
"API_SERVER",
|
||||
"SERVICE_ACCOUNT",
|
||||
"WAIT",
|
||||
"FORCE",
|
||||
} {
|
||||
suite.unsetenv(varname)
|
||||
suite.unsetenv("PLUGIN_" + varname)
|
||||
}
|
||||
suite.setenv("PLUGIN_MODE", "iambic")
|
||||
suite.setenv("PLUGIN_ADD_REPOS", "chortle=http://calloo.callay/frabjous/day")
|
||||
suite.setenv("PLUGIN_KUBERNETES_API_SERVER", "http://tumtum.tree")
|
||||
suite.setenv("PLUGIN_KUBERNETES_SERVICE_ACCOUNT", "tulgey")
|
||||
suite.setenv("PLUGIN_WAIT_FOR_UPGRADE", "true")
|
||||
suite.setenv("PLUGIN_FORCE_UPGRADE", "true")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal("iambic", cfg.Command)
|
||||
suite.Equal([]string{"chortle=http://calloo.callay/frabjous/day"}, cfg.AddRepos)
|
||||
suite.Equal("http://tumtum.tree", cfg.APIServer)
|
||||
suite.Equal("tulgey", cfg.ServiceAccount)
|
||||
suite.True(cfg.Wait, "Wait should be aliased")
|
||||
suite.True(cfg.Force, "Force should be aliased")
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {
|
||||
stdout := &strings.Builder{}
|
||||
stderr := &strings.Builder{}
|
||||
|
|
Loading…
Reference in a new issue