Add --delete operation

This commit is contained in:
Jon Kunkee 2020-06-27 20:21:06 -07:00
parent f28f96c27f
commit 4dfee8cfd6
4 changed files with 29 additions and 0 deletions

View file

@ -11,6 +11,7 @@ namespace NBTUtil
Print,
PrintTree,
SetValue,
DeleteValue,
SetList,
Json,
Help,
@ -64,6 +65,7 @@ namespace NBTUtil
break;
}
}},
{ "delete", "Delete the NBT tag if found", v => Command = ConsoleCommand.DeleteValue },
};
}

View file

@ -13,6 +13,7 @@ namespace NBTUtil
{
private static readonly Dictionary<ConsoleCommand, ConsoleOperation> _commandTable = new Dictionary<ConsoleCommand, ConsoleOperation>() {
{ ConsoleCommand.SetValue, new EditOperation() },
{ ConsoleCommand.DeleteValue, new DeleteOperation() },
{ ConsoleCommand.SetList, new SetListOperation() },
{ ConsoleCommand.Print, new PrintOperation() },
{ ConsoleCommand.PrintTree, new PrintTreeOperation() },

View file

@ -45,6 +45,7 @@
<Compile Include="ConsoleRunner.cs" />
<Compile Include="NDesk\Options.cs" />
<Compile Include="Ops\ConsoleOperation.cs" />
<Compile Include="Ops\DeleteOperation.cs" />
<Compile Include="Ops\EditOperation.cs" />
<Compile Include="Ops\JsonOperation.cs" />
<Compile Include="Ops\PrintOperation.cs" />

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using NBTExplorer.Model;
namespace NBTUtil.Ops
{
class DeleteOperation : ConsoleOperation
{
public override bool OptionsValid (ConsoleOptions options)
{
return true;
}
public override bool CanProcess (DataNode dataNode)
{
return (dataNode != null) && dataNode.CanDeleteNode && (dataNode.Root != dataNode);
}
public override bool Process (DataNode dataNode, ConsoleOptions options)
{
return dataNode.DeleteNode();
}
}
}