comby icon indicating copy to clipboard operation
comby copied to clipboard

Feature request: Multiple rewrites in a single command.

Open Sintrastes opened this issue 4 years ago • 1 comments

Consider the following sequence of comby re-writes used to refactor an Option-like data structure to just using nullable types in

comby 'AlertResult<:[x]>' ':[x]?' -in-place .kt
comby 'AlertResult.Ok(:[x])' ':[x]' -in-place .kt
comby 'AlertResult.Canceled()' 'null' -in-place .kt

It would be convenient if we could write this like the following, so that the -in-place and .kt pieces don't have to be repeated, and we can use a single command:

comby 'AlertResult<:[x]>' ':[x]?' \
   'AlertResult.Ok(:[x])' ':[x]' \
   'AlertResult.Canceled()' 'null' -in-place .kt

Sintrastes avatar Dec 13 '21 16:12 Sintrastes

The closest thing to achieve this right now is via a config file. This doesn't give the convenience of a command line though. A sequence of anonymous arguments like in the single command you put is tricky to support, because there are some other assumptions on what the shape of anonymous arguments mean.

A better solution is to express multiple rewrites in a single command, where that command is a script in a comby DSL, which is something I've made some progress on, but unlikely to happen very very soon. You can imagine something like this, where can sequence multiple x -> y rewrites with ;

comby -script 'AlertResult<:[x]> -> :[x]?; AlertResult.Ok(:[x]) -> :[x]; AlertResult.Canceled() -> null' .kt

This would also supersede the more heavy/awkward config files

rvantonder avatar Jan 09 '22 02:01 rvantonder