From 42a5734b56a8f1ee821482f0c7f345d75358b7f8 Mon Sep 17 00:00:00 2001 From: Tanner Lake Date: Fri, 15 Nov 2019 11:52:16 -0800 Subject: [PATCH] Implement --verbose flag (#3) * add verbose flag * print filtered-out task definition arns when verbose --- cmd/ecs_task.go | 3 +++ ecstask/ecs_task.go | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cmd/ecs_task.go b/cmd/ecs_task.go index 49e8f10..2742907 100644 --- a/cmd/ecs_task.go +++ b/cmd/ecs_task.go @@ -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) @@ -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(¶llelFlag, "parallel", "p", 10, "how many concurrent deregistration requests to make") ecsTaskCmd.Flags().StringVarP(®ionFlag, "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) } diff --git a/ecstask/ecs_task.go b/ecstask/ecs_task.go index 8d479e0..d54434f 100644 --- a/ecstask/ecs_task.go +++ b/ecstask/ecs_task.go @@ -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) @@ -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) @@ -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)