You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/12 07:21:36 UTC

[camel-k] 02/02: Support set integration name for kamel run, sanitize the name

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch integration-name
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 7999a42e4c388f4d7d52b92843663e789e9a01be
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Sep 12 09:20:56 2018 +0200

    Support set integration name for kamel run, sanitize the name
---
 pkg/client/cmd/run.go           | 3 ++-
 pkg/util/kubernetes/sanitize.go | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/pkg/client/cmd/run.go b/pkg/client/cmd/run.go
index 964b9cc..aacb05c 100644
--- a/pkg/client/cmd/run.go
+++ b/pkg/client/cmd/run.go
@@ -52,7 +52,7 @@ func NewCmdRun(rootCmdOptions *RootCmdOptions) *cobra.Command {
 	}
 
 	cmd.Flags().StringVarP(&options.Language, "language", "l", "", "Programming Language used to write the file")
-	cmd.Flags().StringVarP(&options.IntegrationName, "integrationName", "i", "", "The integration name")
+	cmd.Flags().StringVarP(&options.IntegrationName, "name", "", "", "The integration name")
 	cmd.ParseFlags(os.Args)
 
 	return &cmd
@@ -82,6 +82,7 @@ func (o *RunCmdOptions) run(cmd *cobra.Command, args []string) error {
 	name := ""
 	if o.IntegrationName != "" {
 		name = o.IntegrationName
+		name = kubernetes.SanitizeName(name)
 	} else {
 		name = kubernetes.SanitizeName(args[0])
 		if name == "" {
diff --git a/pkg/util/kubernetes/sanitize.go b/pkg/util/kubernetes/sanitize.go
index cb6b823..e42c554 100644
--- a/pkg/util/kubernetes/sanitize.go
+++ b/pkg/util/kubernetes/sanitize.go
@@ -18,9 +18,12 @@ limitations under the License.
 package kubernetes
 
 import (
+	"path"
 	"regexp"
 	"strings"
 	"unicode"
+
+	"github.com/stoewer/go-strcase"
 )
 
 var disallowedChars *regexp.Regexp
@@ -31,7 +34,9 @@ func init() {
 
 func SanitizeName(name string) string {
 	name = strings.Split(name, ".")[0]
+	name = path.Base(name)
 	name = strings.ToLower(name)
+	name = strcase.KebabCase(name)
 	name = disallowedChars.ReplaceAllString(name, "")
 	name = strings.TrimFunc(name, isDisallowedStartEndChar)
 	return name