From 1e1afbffe94ef799c293ac4250be9ae06b1bf099 Mon Sep 17 00:00:00 2001 From: wuqixuan Date: Thu, 18 Jun 2015 15:30:31 +0800 Subject: [PATCH] fleetctl: destroy using wildcards can search in the repository Curerntly, fleetctl destroy *.service, it will search the units in the local directory. The args with wildcards have already parsed by golang package before be passed into runDestroyUnits. So runDestroyUnits cannot do anything. This patch support wildcards just search in the repository, not from local directory. But need support a new interface. The new interface is: fleetctl destroy "xx*.service". We found that if bracket the service name, the arg will not be parsed by golang package to local directory. Then we can do match it with the service name in the repository. Fixes #710 --- fleetctl/destroy.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/fleetctl/destroy.go b/fleetctl/destroy.go index d00778aa1..cf952d0ea 100644 --- a/fleetctl/destroy.go +++ b/fleetctl/destroy.go @@ -14,6 +14,10 @@ package main +import ( + "path" +) + var cmdDestroyUnit = &Command{ Name: "destroy", Summary: "Destroy one or more units in the cluster", @@ -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 }