From e1b92fc5276833ea80101786bcd0c386b0bfb136 Mon Sep 17 00:00:00 2001 From: Vladimir Moskva Date: Wed, 14 Feb 2024 17:06:42 +0100 Subject: [PATCH] Add a new command set_encoded --- edit/buildozer.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/edit/buildozer.go b/edit/buildozer.go index 486d71f63..ae6fa65fd 100644 --- a/edit/buildozer.go +++ b/edit/buildozer.go @@ -563,6 +563,23 @@ func cmdSet(opts *Options, env CmdEnvironment) (*build.File, error) { return env.File, nil } +func cmdSetEncoded(opts *Options, env CmdEnvironment) (*build.File, error) { + attr := env.Args[0] + args := env.Args[1:] + var decoded = strings.Replace(args[0], "%0A", "\n", -1) + decoded = strings.Replace(decoded, "%0D", "\r", -1) + decoded = strings.Replace(decoded, "%20", " ", -1) + decoded = strings.Replace(decoded, "%25", "%", -1) + if attr == "kind" { + env.Rule.SetKind(decoded) + } else { + var decodedArgs []string + decodedArgs = append(decodedArgs, decoded) + env.Rule.SetAttr(attr, getAttrValueExpr(attr, decodedArgs, env)) + } + return env.File, nil +} + func cmdSetIfAbsent(opts *Options, env CmdEnvironment) (*build.File, error) { attr := env.Args[0] args := env.Args[1:] @@ -898,6 +915,7 @@ var AllCommands = map[string]CommandInfo{ "replace": {cmdReplace, true, 3, 3, " "}, "substitute": {cmdSubstitute, true, 3, 3, " "}, "set": {cmdSet, true, 1, -1, " "}, + "set_encoded": {cmdSetEncoded, true, 1, -1, " "}, "set_if_absent": {cmdSetIfAbsent, true, 1, -1, " "}, "set_select": {cmdSetSelect, true, 1, -1, " "}, "copy": {cmdCopy, true, 2, 2, " "},