Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize user properties over modeline properties. #1857

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion pkg/cmd/modeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: <name>=<value>
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++
}
Expand Down