Skip to content

Commit

Permalink
Merge pull request #634 from kayac/refactor-filter-command
Browse files Browse the repository at this point in the history
ECSPRESSO_FILTER_COMMAND moves to cli flag.
  • Loading branch information
fujiwara authored Dec 1, 2023
2 parents aa75636 + 0508ce1 commit b2c2982
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 4 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions ecspresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit b2c2982

Please sign in to comment.