|
1 | 1 | import os |
2 | 2 | from collections.abc import Sequence |
| 3 | +from pathlib import Path |
3 | 4 |
|
4 | 5 | from cedarscript_ast_parser import Command, RmFileCommand, MvFileCommand, UpdateCommand, \ |
5 | 6 | SelectCommand, IdentifierFromFile, Segment, Marker, MoveClause, DeleteClause, \ |
@@ -65,7 +66,7 @@ def __init__(self, command_ordinal: int, description: str): |
65 | 66 |
|
66 | 67 | class CEDARScriptEditor: |
67 | 68 | def __init__(self, root_path: os.PathLike): |
68 | | - self.root_path = os.path.abspath(root_path) |
| 69 | + self.root_path = Path(os.path.abspath(root_path)) |
69 | 70 | print(f'[{self.__class__.__name__}] root: {self.root_path}') |
70 | 71 |
|
71 | 72 | # TODO Add 'target_search_range: RangeSpec' parameter |
@@ -257,14 +258,14 @@ def _rm_command(self, cmd: RmFileCommand): |
257 | 258 | def _delete_function(self, cmd): # TODO |
258 | 259 | file_path = os.path.join(self.root_path, cmd.file_path) |
259 | 260 |
|
260 | | - # def _create_command(self, cmd: CreateCommand): |
261 | | - # file_path = os.path.join(self.root_path, cmd.file_path) |
262 | | - # |
263 | | - # os.makedirs(os.path.dirname(file_path), exist_ok=False) |
264 | | - # with open(file_path, 'w') as file: |
265 | | - # file.write(content) |
266 | | - # |
267 | | - # return f"Created file: {command['file']}" |
| 261 | + def _create_command(self, cmd: CreateCommand): |
| 262 | + file_path = os.path.join(self.root_path, cmd.file_path) |
| 263 | + |
| 264 | + os.makedirs(os.path.dirname(file_path), exist_ok=True) |
| 265 | + with open(file_path, 'w') as file: |
| 266 | + file.write(cmd.content) |
| 267 | + |
| 268 | + return f"Created file: {cmd.file_path}" |
268 | 269 |
|
269 | 270 |
|
270 | 271 | def find_index_range_for_region(region: BodyOrWhole | Marker | Segment | RelativeMarker, |
|
0 commit comments