Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

fleetctl: destroy using wildcards can search in the repository #1256

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions fleetctl/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package main

import (
"path"
)

var cmdDestroyUnit = &Command{
Name: "destroy",
Summary: "Destroy one or more units in the cluster",
Expand All @@ -29,14 +33,27 @@ Destroyed units are impossible to start unless re-submitted.`,
}

func runDestroyUnits(args []string) (exit int) {
states, err := cAPI.UnitStates()
if err != nil {
stderr("Error retrieving list of units from repository: %v", err)
return 1
}

for _, v := range args {
name := unitNameMangle(v)
err := cAPI.DestroyUnit(name)
if err != nil {
continue
}
for _, us := range states {
if match, _ := path.Match(name, us.Name); match == false {
continue
}

err = cAPI.DestroyUnit(us.Name)
if err != nil {
stderr("Error destroying unit %s: %v", us.Name, err)
continue
}

stdout("Destroyed %s", name)
stdout("Destroyed %s", us.Name)
}
}
return
}