-
Notifications
You must be signed in to change notification settings - Fork 1
Added capability to applypatch -> replaceText to replace the header along with the content #2
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
Closed
taylor-hutyra
wants to merge
1
commit into
coddingtonbear:main
from
taylor-hutyra:feature/replaceheader
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,10 @@ program | |
| "Heading delimiter to use in place of '::'.", | ||
| "::" | ||
| ) | ||
| .option( | ||
| "--replace-heading", | ||
| "Replace the heading as well as its content." | ||
| ) | ||
| .argument("<operation>", "Operation to perform ('replace', 'append', etc.)") | ||
| .argument("<targetType>", "Target type ('heading', 'block', etc.)") | ||
| .argument( | ||
|
|
@@ -77,13 +81,34 @@ program | |
|
|
||
| const document = await fs.readFile(documentPath, "utf-8"); | ||
|
|
||
| const instruction = { | ||
| operation, | ||
| targetType, | ||
| content, | ||
| target: | ||
| targetType !== "heading" ? target : target.split(options.delimiter), | ||
| } as PatchInstruction; | ||
| let instruction: PatchInstruction; | ||
|
|
||
| // Only create a ReplaceHeadingPatchInstruction when the operation and target are correct | ||
| if (operation === "replace" && targetType === "heading") { | ||
| instruction = { | ||
| operation, | ||
| targetType, | ||
| content, | ||
| target: target.split(options.delimiter), | ||
| replaceHeading: options.replaceHeading, | ||
| }; | ||
| } else { | ||
| // If the user tries to use the flag incorrectly, exit with an error. | ||
| if (options.replaceHeading) { | ||
| console.error( | ||
| "The --replace-heading flag is only valid for 'replace' operations on 'heading' targets." | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| // Create other instruction types as before | ||
| instruction = { | ||
| operation, | ||
| targetType, | ||
| content, | ||
| target: | ||
| targetType !== "heading" ? target : target.split(options.delimiter), | ||
| } as PatchInstruction; | ||
| } | ||
|
Comment on lines
+87
to
+111
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the answer to the above question will probably help me understand the answer to this one, but in case it doesn't: I'm finding myself wondering why we can't just read the |
||
|
|
||
| const patchedDocument = applyPatch(document, instruction); | ||
| if (options.output === "-") { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a little bit surprising to me that this would be a global option for the patch applier when that particular option is only valid for certain kinds of patch instructions; what was your intention here?