mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-04 05:28:02 +00:00
Add next invocation
command to fake-editor
This adds a `next invocation` command to `fake-editor` that ignores the rest of the script for *this* invocation, but overwrites the script with whatever follows `next invocation`. This is useful to test commands that invoke `fake-editor` several times, especially the `jj split` command.
This commit is contained in:
parent
0b528eb587
commit
2150166652
1 changed files with 10 additions and 2 deletions
|
@ -30,8 +30,16 @@ struct Args {
|
|||
fn main() {
|
||||
let args: Args = Args::parse();
|
||||
let edit_script_path = PathBuf::from(std::env::var_os("EDIT_SCRIPT").unwrap());
|
||||
let edit_script = String::from_utf8(std::fs::read(edit_script_path).unwrap()).unwrap();
|
||||
for instruction in edit_script.split('\0') {
|
||||
let edit_script = String::from_utf8(std::fs::read(edit_script_path.clone()).unwrap()).unwrap();
|
||||
|
||||
let mut instructions = edit_script.split('\0').collect_vec();
|
||||
if let Some(pos) = instructions.iter().position(|&i| i == "next invocation\n") {
|
||||
// Overwrite the edit script. The next time `fake-editor` is called, it will
|
||||
// only see the part after the `next invocation` command.
|
||||
std::fs::write(edit_script_path, instructions[pos + 1..].join("\0")).unwrap();
|
||||
instructions.truncate(pos);
|
||||
}
|
||||
for instruction in instructions {
|
||||
let (command, payload) = instruction.split_once('\n').unwrap_or((instruction, ""));
|
||||
let parts = command.split(' ').collect_vec();
|
||||
match parts.as_slice() {
|
||||
|
|
Loading…
Reference in a new issue