Ranamed modify_file's 'insert' operation to 'insert_before'

This commit is contained in:
Matt Low 2023-11-26 15:51:04 +00:00
parent 5c1f7e2594
commit 2f6c8006d0

View File

@ -168,7 +168,7 @@ To replace or remove a single line, *set start_line and end_line to the same val
Examples:
* Insert the lines "hello<new line>world" at line 10, preserving other content:
{"path": "myfile", "operation": "insert", "start_line": 10, "content": "hello\nworld"}
{"path": "myfile", "operation": "insert_before", "start_line": 10, "content": "hello\nworld"}
* Remove lines 45 up to and including 54:
{"path": "myfile", "operation": "remove", "start_line": 45, "end_line": 54}
@ -187,7 +187,7 @@ Examples:
},
"operation": {
Type: "string",
Description: `The the type of modification to make to the file. One of: insert, remove, replace`,
Description: `The the type of modification to make to the file. One of: insert_before, remove, replace`,
},
"start_line": {
Type: "integer",
@ -478,7 +478,7 @@ func ModifyFile(path string, operation string, content string, startLine int, en
contentLines := strings.Split(strings.Trim(content, "\n"), "\n")
switch operation {
case "insert":
case "insert_before":
// Insert new lines
before := lines[:startLine-1]
after := append(contentLines, lines[startLine-1:]...)