Skip to content

Commit

Permalink
Fixes apache#515 Allow file names as delete cmd argument
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd authored and ipolyzos committed Jul 31, 2019
1 parent 7099b13 commit 05fe0f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strconv"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/spf13/cobra"
k8errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -77,16 +78,16 @@ func (command *deleteCmdOptions) run(args []string) error {
}
if len(args) != 0 && !command.deleteAll {
for _, arg := range args {

err := DeleteIntegration(command.Context, c, arg, command.Namespace)
name := kubernetes.SanitizeName(arg)
err := DeleteIntegration(command.Context, c, name, command.Namespace)
if err != nil {
if k8errors.IsNotFound(err) {
fmt.Println("Integration " + arg + " not found. Skipped.")
fmt.Println("Integration " + name + " not found. Skipped.")
} else {
return err
}
} else {
fmt.Println("Integration " + arg + " deleted")
fmt.Println("Integration " + name + " deleted")
}
}
} else if command.deleteAll {
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/kubernetes/sanitize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestSanitizeName(t *testing.T) {
{"input": "/path/to/abc.js", "expect": "abc"},
{"input": "abc.xml", "expect": "abc"},
{"input": "./path/to/abc.kts", "expect": "abc"},
{"input": "fooToBar.groovy", "expect": "foo-to-bar"},
{"input": "foo-to-bar", "expect": "foo-to-bar"},
}

for _, c := range cases {
Expand Down

0 comments on commit 05fe0f9

Please sign in to comment.