diff --git a/config.go b/config.go index e2178b7d..add43823 100644 --- a/config.go +++ b/config.go @@ -116,6 +116,9 @@ func (c *Config) OverrideByOption(opt *Option) { if opt.Timeout != nil { c.Timeout = &Duration{*opt.Timeout} } + if opt.FilterCommand != "" { + c.FilterCommand = opt.FilterCommand + } } // Restrict restricts a configuration. @@ -164,9 +167,8 @@ func (c *Config) Restrict(ctx context.Context) error { if err := c.setupPlugins(ctx); err != nil { return fmt.Errorf("failed to setup plugins: %w", err) } - if c.FilterCommand != "" { - Log("[WARNING] filter_command is deprecated. Use %s environment variable instead.", FilterCommandEnv) + Log("[WARNING] filter_command is deprecated. Use environment variable or CLI flag instead.") } return nil } diff --git a/config_test.go b/config_test.go index 39b69609..51d17c75 100644 --- a/config_test.go +++ b/config_test.go @@ -311,9 +311,9 @@ var FilterCommandTests = []struct { func TestFilterCommandDeprecated(t *testing.T) { ctx := context.Background() for _, ts := range FilterCommandTests { - t.Setenv("ECSPRESSO_FILTER_COMMAND", ts.Env) app, err := ecspresso.New(ctx, &ecspresso.Option{ ConfigFilePath: "tests/filter_command.yml", + FilterCommand: ts.Env, }) if err != nil { t.Error(err) diff --git a/ecspresso.go b/ecspresso.go index 23b6668d..3c2a9abb 100644 --- a/ecspresso.go +++ b/ecspresso.go @@ -31,7 +31,6 @@ import ( const DefaultDesiredCount = -1 const DefaultConfigFilePath = "ecspresso.yml" const dryRunStr = "DRY RUN" -const FilterCommandEnv = "ECSPRESSO_FILTER_COMMAND" var Version string var delayForServiceChanged = 3 * time.Second @@ -184,6 +183,7 @@ type Option struct { ConfigFilePath string `name:"config" help:"config file" default:"ecspresso.yml" env:"ECSPRESSO_CONFIG"` AssumeRoleARN string `help:"the ARN of the role to assume" default:"" env:"ECSPRESSO_ASSUME_ROLE_ARN"` Timeout *time.Duration `help:"timeout. Override in a configuration file." env:"ECSPRESSO_TIMEOUT"` + FilterCommand string `help:"filter command" env:"ECSPRESSO_FILTER_COMMAND"` } func (opt *Option) resolveConfigFilePath() (path string) { @@ -538,8 +538,5 @@ func (d *App) GetLogInfo(task *types.Task, c *types.ContainerDefinition) (string } func (d *App) FilterCommand() string { - if fc := os.Getenv(FilterCommandEnv); fc != "" { - return fc - } return d.config.FilterCommand }