Skip to content

Commit

Permalink
Merge pull request #565 from kayac/refactor-options-type
Browse files Browse the repository at this point in the history
Refactor options type
  • Loading branch information
fujiwara committed May 18, 2023
2 parents 1511ff9 + b4482b8 commit b350ae7
Show file tree
Hide file tree
Showing 22 changed files with 502 additions and 435 deletions.
12 changes: 5 additions & 7 deletions appspec.go
Expand Up @@ -5,13 +5,12 @@ import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/kayac/ecspresso/v2/appspec"
)

type AppSpecOption struct {
TaskDefinition *string `help:"use task definition arn in AppSpec (latest, current or Arn)" default:"latest"`
UpdateService *bool `help:"update service definition with task definition arn" default:"true" negatable:""`
TaskDefinition string `help:"use task definition arn in AppSpec (latest, current or Arn)" default:"latest"`
UpdateService bool `help:"update service definition with task definition arn" default:"true" negatable:""`
}

func (d *App) AppSpec(ctx context.Context, opt AppSpecOption) error {
Expand All @@ -23,7 +22,7 @@ func (d *App) AppSpec(ctx context.Context, opt AppSpecOption) error {
if err != nil {
return err
}
switch *opt.TaskDefinition {
switch opt.TaskDefinition {
case "current":
taskDefinitionArn = *sv.TaskDefinition
case "latest":
Expand All @@ -33,12 +32,11 @@ func (d *App) AppSpec(ctx context.Context, opt AppSpecOption) error {
return err
}
default:
taskDefinitionArn = *opt.TaskDefinition
if !strings.HasPrefix(taskDefinitionArn, "arn:aws:ecs:") {
if !strings.HasPrefix(opt.TaskDefinition, "arn:aws:ecs:") {
return fmt.Errorf("--task-definition requires current, latest or a valid task definition arn")
}
}
if aws.ToBool(opt.UpdateService) {
if opt.UpdateService {
newSv, err := d.LoadServiceDefinition(d.config.ServiceDefinitionPath)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion autoscaling.go
Expand Up @@ -68,7 +68,7 @@ func (d *App) modifyAutoScaling(ctx context.Context, opt DeployOption) error {
return nil
}

if *opt.DryRun {
if opt.DryRun {
return nil
}
for _, target := range out.ScalableTargets {
Expand Down

0 comments on commit b350ae7

Please sign in to comment.