Skip to content

Commit

Permalink
prints resources before deleting them instead of after (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonderops authored and jckuester committed Jan 16, 2020
1 parent 7126484 commit 01d7b20
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions command/wipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ type Wipe struct {
outputType string
}

func Info(c *Wipe, v string) {
for _, resType := range c.filter.Types() {
rawResources, err := c.client.RawResources(resType)
if err != nil {
log.Fatal(err)
}

deletableResources, err := resource.DeletableResources(resType, rawResources)
if err != nil {
log.Fatal(err)
}

filteredRes := c.filter.Apply(resType, deletableResources, rawResources, c.client)
for _, res := range filteredRes {
print(res, c.outputType)
if !c.dryRun && v == "yes" {
c.wipe(res)
}
}
}
}

// Run executes the wipe command.
func (c *Wipe) Run(args []string) int {
if len(args) == 1 {
Expand All @@ -43,6 +65,8 @@ func (c *Wipe) Run(args []string) int {
return 1
}

Info(c, "print")

if c.dryRun {
logrus.Info("This is a test run, nothing will be deleted!")
} else if !c.forceDelete {
Expand All @@ -58,26 +82,7 @@ func (c *Wipe) Run(args []string) int {
if v != "yes" {
return 0
}
}

for _, resType := range c.filter.Types() {
rawResources, err := c.client.RawResources(resType)
if err != nil {
log.Fatal(err)
}

deletableResources, err := resource.DeletableResources(resType, rawResources)
if err != nil {
log.Fatal(err)
}

filteredRes := c.filter.Apply(resType, deletableResources, rawResources, c.client)
for _, res := range filteredRes {
print(res, c.outputType)
if !c.dryRun {
c.wipe(res)
}
}
Info(c, v)
}

return 0
Expand Down

0 comments on commit 01d7b20

Please sign in to comment.