From d11ecbc773a4776dc699c55fd3d728678a55b177 Mon Sep 17 00:00:00 2001 From: Doru Bercea Date: Thu, 10 Dec 2020 17:10:07 -0500 Subject: [PATCH] Prioritize user properties over modeline properties. --- pkg/cmd/modeline.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go index 53441363a6..14258dc1cd 100644 --- a/pkg/cmd/modeline.go +++ b/pkg/cmd/modeline.go @@ -123,10 +123,35 @@ func createKamelWithModelineCommand(ctx context.Context, args []string) (*cobra. return nil, nil, errors.Wrap(err, "cannot read sources") } + // Extract list of property names already specified by the user. + userPropertyNames := []string{} + index := 0 + for _, arg := range args { + if arg == "-p" || arg == "--property" { + // Property is assumed to be in the form: = + splitValues := strings.Split(args[index+1], "=") + userPropertyNames = append(userPropertyNames, splitValues[0]) + } + index++ + } + // filter out in place non-run options nOpts := 0 for _, o := range opts { - if !nonRunOptions[o.Name] { + // Check if property name is given by user. + propertyAlreadySpecifiedByUser := false + if o.Name == "property" { + propertyComponents := strings.Split(o.Value, "=") + for _, propName := range userPropertyNames { + if propName == propertyComponents[0] { + propertyAlreadySpecifiedByUser = true + break + } + } + } + + // Skip properties already specified by the user otherwise add all options. + if !propertyAlreadySpecifiedByUser && !nonRunOptions[o.Name] { opts[nOpts] = o nOpts++ }