github.com/chenbh/concourse/v6@v6.4.2/fly/commands/clear_task_cache.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/chenbh/concourse/v6/fly/commands/internal/flaghelpers" 7 "github.com/chenbh/concourse/v6/fly/rc" 8 "github.com/vito/go-interact/interact" 9 ) 10 11 type ClearTaskCacheCommand struct { 12 Job flaghelpers.JobFlag `short:"j" long:"job" required:"true" description:"Job to clear cache from"` 13 StepName string `short:"s" long:"step" required:"true" description:"Step name to clear cache from"` 14 CachePath string `short:"c" long:"cache-path" default:"" description:"Cache directory to clear out"` 15 SkipInteractive bool `short:"n" long:"non-interactive" description:"Destroy the task cache(s) without confirmation"` 16 } 17 18 func (command *ClearTaskCacheCommand) Execute([]string) error { 19 target, err := rc.LoadTarget(Fly.Target, Fly.Verbose) 20 if err != nil { 21 return err 22 } 23 24 err = target.Validate() 25 if err != nil { 26 return err 27 } 28 29 warningMsg := fmt.Sprintf("!!! this will remove the task cache(s) for `%s/%s`, task step `%s`", 30 command.Job.PipelineName, command.Job.JobName, command.StepName) 31 if len(command.CachePath) > 0 { 32 warningMsg += fmt.Sprintf(", at `%s`", command.CachePath) 33 } 34 warningMsg += "\n" 35 fmt.Println(warningMsg) 36 37 confirm := command.SkipInteractive 38 if !confirm { 39 err := interact.NewInteraction("are you sure?").Resolve(&confirm) 40 if err != nil || !confirm { 41 fmt.Println("bailing out") 42 return err 43 } 44 } 45 46 numRemoved, err := target.Team().ClearTaskCache(command.Job.PipelineName, command.Job.JobName, command.StepName, command.CachePath) 47 48 if err != nil { 49 fmt.Println(err.Error()) 50 return err 51 } else { 52 fmt.Printf("%d caches removed\n", numRemoved) 53 return nil 54 } 55 }