feat: Introduce robust hashline anchor validation and new editing tools.
This commit is contained in:
@@ -66,7 +66,7 @@ internal static partial class EditTools
|
||||
Log($" Replacing {endAnchor.Split(':')[0]}-{startAnchor.Split(':')[0]} lines with {newLines.Length} new lines");
|
||||
|
||||
if (!File.Exists(path))
|
||||
return $"ERROR: File not found: {path}";
|
||||
return $"ERROR: File not found: {path}\n Check the correct path and try again.";
|
||||
|
||||
try
|
||||
{
|
||||
@@ -74,7 +74,7 @@ internal static partial class EditTools
|
||||
|
||||
if (!HashlineValidator.TryResolveRange(startAnchor, endAnchor, lines,
|
||||
out int startIdx, out int endIdx, out string error))
|
||||
return $"ERROR: {error}";
|
||||
return $"ERROR: Anchor validation failed\n{error}";
|
||||
|
||||
var result = new List<string>(lines.Length - (endIdx - startIdx + 1) + newLines.Length);
|
||||
result.AddRange(lines[..startIdx]);
|
||||
@@ -86,7 +86,7 @@ internal static partial class EditTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"ERROR modifying '{path}': {ex.Message}";
|
||||
return $"ERROR modifying '{path}': {ex.Message}.\nThis is a bug. Tell the user about it.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,22 +120,22 @@ internal static partial class EditTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"ERROR modifying '{path}': {ex.Message}";
|
||||
return $"ERROR modifying '{path}': {ex.Message}\nThis is a bug. Tell the user about it.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Description("Delete a file or directory. Use mode='file' to delete a file, mode='dir' to delete a directory.")]
|
||||
[Description("Delete a file or directory. Use mode='file' to delete a file, mode='dir' to delete a directory.")]
|
||||
public static string Delete(
|
||||
[Description("Path to the file or directory to delete.")] string path,
|
||||
[Description("Type of deletion: 'file' or 'dir'. Defaults to 'file'.")] string mode = "file")
|
||||
{
|
||||
path = FileTools.ResolvePath(path);
|
||||
string targetType = mode.ToLower() == "dir" ? "directory" : "file";
|
||||
string targetType = mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase) ? "directory" : "file";
|
||||
Log($"Deleting {targetType}: {path}");
|
||||
|
||||
if (mode.ToLower() == "dir")
|
||||
if (mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
return $"ERROR: Directory not found: {path}";
|
||||
@@ -147,7 +147,7 @@ internal static partial class EditTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"ERROR deleting directory '{path}': {ex.Message}";
|
||||
return $"ERROR deleting directory '{path}': {ex.Message}\nThis is a bug. Tell the user about it.";
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -162,12 +162,12 @@ internal static partial class EditTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"ERROR deleting '{path}': {ex.Message}";
|
||||
return $"ERROR deleting '{path}': {ex.Message}\nThis is a bug. Tell the user about it.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Move or copy a file to a new location.")]
|
||||
[Description("Move or copy a file to a new location.")]
|
||||
public static string MoveFile(
|
||||
[Description("Current path to the file.")] string sourcePath,
|
||||
[Description("New path for the file.")] string destinationPath,
|
||||
@@ -198,7 +198,7 @@ internal static partial class EditTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"ERROR {action.ToLower()} file: {ex.Message}";
|
||||
return $"ERROR {action.ToLower()} file: {ex.Message}\nThis is a bug. Tell the user about it.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ internal static partial class EditTools
|
||||
File.WriteAllText(path, "");
|
||||
Log($" (created new file)");
|
||||
}
|
||||
|
||||
|
||||
using (var writer = new System.IO.StreamWriter(path, true))
|
||||
{
|
||||
foreach (var line in content)
|
||||
@@ -279,7 +279,7 @@ internal static partial class EditTools
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"ERROR writing to '{path}': {ex.Message}";
|
||||
return $"ERROR writing to '{path}': {ex.Message}\nThis is a bug. Tell the user about it.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user