diff --git a/pkg/kn/commands/service/delete.go b/pkg/kn/commands/service/delete.go index b47634ab08..77f39316c4 100644 --- a/pkg/kn/commands/service/delete.go +++ b/pkg/kn/commands/service/delete.go @@ -35,9 +35,10 @@ func NewServiceDeleteCommand(p *commands.KnParams) *cobra.Command { kn service delete svc2 -n ns1`, RunE: func(cmd *cobra.Command, args []string) error { - if len(args) != 1 { + if len(args) < 1 { return errors.New("requires the service name.") } + namespace, err := p.GetNamespace(cmd) if err != nil { return err @@ -47,11 +48,13 @@ func NewServiceDeleteCommand(p *commands.KnParams) *cobra.Command { return err } - err = client.DeleteService(args[0]) - if err != nil { - return err + for _, name := range args { + err = client.DeleteService(name) + if err != nil { + return err + } + fmt.Fprintf(cmd.OutOrStdout(), "Service '%s' successfully deleted in namespace '%s'.\n", name, namespace) } - fmt.Fprintf(cmd.OutOrStdout(), "Service '%s' successfully deleted in namespace '%s'.\n", args[0], namespace) return nil }, } diff --git a/pkg/kn/commands/service/delete_test.go b/pkg/kn/commands/service/delete_test.go index f1137a69d3..68dc7ba987 100644 --- a/pkg/kn/commands/service/delete_test.go +++ b/pkg/kn/commands/service/delete_test.go @@ -59,3 +59,22 @@ func TestServiceDelete(t *testing.T) { } assert.Check(t, util.ContainsAll(output, "Service", sevName, "deleted", "namespace", commands.FakeNamespace)) } + +func TestMultipleServiceDelete(t *testing.T) { + sevName1 := "sev-12345" + sevName2 := "sev-67890" + sevName3 := "sev-abcde" + action, _, output, err := fakeServiceDelete([]string{"service", "delete", sevName1, sevName2, sevName3}) + if err != nil { + t.Error(err) + return + } + if action == nil { + t.Errorf("No action") + } else if !action.Matches("delete", "services") { + t.Errorf("Bad action %v", action) + } + assert.Check(t, util.ContainsAll(output, "Service", sevName1, "deleted", "namespace", commands.FakeNamespace)) + assert.Check(t, util.ContainsAll(output, "Service", sevName2, "deleted", "namespace", commands.FakeNamespace)) + assert.Check(t, util.ContainsAll(output, "Service", sevName3, "deleted", "namespace", commands.FakeNamespace)) +}