Replace a string in all posts

This should be fine… but one of the problems is that it looks like you can quote other things such as commas, but you can’t since the quotes are consumed by the shell, not by the rake parser.

e.g.:

→ rake posts:remap["a,b","a+b"]
ERROR: Expecting rake posts:remap['find','replace',type] where type is string or regex

And the brackets should be quoted since they’re shell metachars themselves. You won’t even be able to run the command with a file called posts:remapa in the directory (unlikely as this may be) or with failglob set.

I think we should change these commands - they’re misleading in the sense that they look like you’re quoting the strings being replaced, but we really aren’t. The quotes are consumed by the shell; rails never sees them. No reason to even have the quotes, and if rails does see them they’ll be part of the string:

→ rake 'posts:remap["find","replace"]'
Are you sure you want to replace all string occurrences of '"find"' with '"replace"'? (Y/n)

Some more examples including how to deal with things like commas are:

rake 'posts:remap[find,replace,string,true]'
rake $'posts:remap[string with a quote\',string without a quote]'
rake 'posts:remap[a\, b,a+b]'

though, quirkily, this works:

→ rake 'posts:remap[string with a bracket] either quoted\] or not,string without a bracket]'
Are you sure you want to replace all string occurrences of 'string with a bracket] either quoted] or not' with 'string without a bracket'? (Y/n)
1 Mi Piace