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

Add a new command set_encoded #1243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions edit/buildozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down Expand Up @@ -898,6 +915,7 @@ var AllCommands = map[string]CommandInfo{
"replace": {cmdReplace, true, 3, 3, "<attr> <old_value> <new_value>"},
"substitute": {cmdSubstitute, true, 3, 3, "<attr> <old_regexp> <new_template>"},
"set": {cmdSet, true, 1, -1, "<attr> <value(s)>"},
"set_encoded": {cmdSetEncoded, true, 1, -1, "<attr> <value(s)>"},
"set_if_absent": {cmdSetIfAbsent, true, 1, -1, "<attr> <value(s)>"},
"set_select": {cmdSetSelect, true, 1, -1, "<attr> <key_1> <value_1> <key_n> <value_n>"},
"copy": {cmdCopy, true, 2, 2, "<attr> <from_rule>"},
Expand Down