diff --git a/bpmodify/bpmodify.go b/bpmodify/bpmodify.go index 0ab9dde..42de70e 100644 --- a/bpmodify/bpmodify.go +++ b/bpmodify/bpmodify.go @@ -230,12 +230,20 @@ func processParameter(value parser.Expression, paramName, moduleName string, } if (*replaceProperty).size() != 0 { - list, ok := value.Eval().(*parser.List) - if !ok { - return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list, found %s", - paramName, moduleName, value.Type().String())} + if list, ok := value.Eval().(*parser.List); ok { + return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil + } else if str, ok := value.Eval().(*parser.String); ok { + oldVal := str.Value + replacementValue := (*replaceProperty).oldNameToNewName[oldVal] + if replacementValue != "" { + str.Value = replacementValue + return true, nil + } else { + return false, nil + } } - return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil + return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list or string, found %s", + paramName, moduleName, value.Type().String())} } if len(addIdents.idents) > 0 || len(removeIdents.idents) > 0 { list, ok := value.(*parser.List) diff --git a/bpmodify/bpmodify_test.go b/bpmodify/bpmodify_test.go index 3924358..f3cbc97 100644 --- a/bpmodify/bpmodify_test.go +++ b/bpmodify/bpmodify_test.go @@ -395,6 +395,46 @@ var testCases = []struct { } `, replaceProperty: "baz:baz_lib,foobar:foobar_lib", + }, { + name: "replace property string value", + property: "name", + input: ` + cc_foo { + name: "foo", + deps: ["baz"], + unchanged: ["baz"], + required: ["foobar"], + } + `, + output: ` + cc_foo { + name: "foo_lib", + deps: ["baz"], + unchanged: ["baz"], + required: ["foobar"], + } + `, + replaceProperty: "foo:foo_lib", + }, { + name: "replace property string and list values", + property: "name,deps", + input: ` + cc_foo { + name: "foo", + deps: ["baz"], + unchanged: ["baz"], + required: ["foobar"], + } + `, + output: ` + cc_foo { + name: "foo_lib", + deps: ["baz_lib"], + unchanged: ["baz"], + required: ["foobar"], + } + `, + replaceProperty: "foo:foo_lib,baz:baz_lib", }, }