Skip to content

Commit

Permalink
Implement --verbose flag (#3)
Browse files Browse the repository at this point in the history
* add verbose flag

* print filtered-out task definition arns when verbose
  • Loading branch information
tlake authored Nov 15, 2019
1 parent 56fbf2b commit 42a5734
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmd/ecs_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ the AWS CLI for the AWS account you want to clean up.`,
"cutoff": cutoffFlag,
"parallel": parallelFlag,
"region": regionFlag,
"verbose": verboseFlag,
}

ecstask.Run(cmd, args, flags)
Expand All @@ -28,11 +29,13 @@ var applyFlag bool
var cutoffFlag int
var parallelFlag int
var regionFlag string
var verboseFlag bool

func init() {
ecsTaskCmd.Flags().BoolVarP(&applyFlag, "apply", "a", false, "actually perform task definition deregistration")
ecsTaskCmd.Flags().IntVarP(&cutoffFlag, "cutoff", "c", 5, "how many most-recent task definitions to keep around")
ecsTaskCmd.Flags().IntVarP(&parallelFlag, "parallel", "p", 10, "how many concurrent deregistration requests to make")
ecsTaskCmd.Flags().StringVarP(&regionFlag, "region", "r", "us-west-2", "the AWS region in which to operate")
ecsTaskCmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "enable for chattier output")
rootCmd.AddCommand(ecsTaskCmd)
}
28 changes: 21 additions & 7 deletions ecstask/ecs_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func Run(cmd *cobra.Command, args []string, flags map[string]interface{}) {
}

fmt.Printf("filtering out %d in-use task definitions\n", len(inUseTaskDefinitionArns))
if flags["verbose"].(bool) {
for _, arn := range inUseTaskDefinitionArns {
fmt.Println(arn)
}
}

allTaskDefinitionArns = removeAFromB(inUseTaskDefinitionArns, allTaskDefinitionArns)

Expand Down Expand Up @@ -219,15 +224,19 @@ func Run(cmd *cobra.Command, args []string, flags map[string]interface{}) {
familyTaskDefinitionArns = append(familyTaskDefinitionArns, arn)
}

fmt.Printf("\r(found %d)", len(familyTaskDefinitionArns))
needToResetPrinter = true
if flags["verbose"].(bool) {
fmt.Printf("\r(found %d)", len(familyTaskDefinitionArns))
needToResetPrinter = true
}
}

if needToResetPrinter {
fmt.Println()
needToResetPrinter = false
} else {
fmt.Printf("(found %d)\n", len(familyTaskDefinitionArns))
if flags["verbose"].(bool) {
if needToResetPrinter {
fmt.Println()
needToResetPrinter = false
} else {
fmt.Printf("(found %d)\n", len(familyTaskDefinitionArns))
}
}

familyTaskDefinitionArns = removeAFromB(inUseTaskDefinitionArns, familyTaskDefinitionArns)
Expand All @@ -244,6 +253,11 @@ func Run(cmd *cobra.Command, args []string, flags map[string]interface{}) {
}

fmt.Printf("filtering out %d recent task definitions across %d families\n", len(mostRecentActiveTaskDefinitionArns), len(inUseTaskDefinitionFamilies))
if flags["verbose"].(bool) {
for _, arn := range mostRecentActiveTaskDefinitionArns {
fmt.Println(arn)
}
}

allTaskDefinitionArns = removeAFromB(mostRecentActiveTaskDefinitionArns, allTaskDefinitionArns)

Expand Down

0 comments on commit 42a5734

Please sign in to comment.