Skip to content

Commit 6e8d25b

Browse files
committed
propmgr: Add "rename" verb
1 parent 5e91197 commit 6e8d25b

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Tools/propmgr/CommandProcessor.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ public ModifyCommand()
8282
}
8383
}
8484

85+
[Verb("rename", HelpText = "Rename existing property.")]
86+
public class RenameCommand: Command
87+
{
88+
[Value(0, MetaName = "prop_name", Required = true, HelpText = "Name of property to rename")]
89+
public string OldName { get; set; }
90+
[Value(1, MetaName = "new_name", Required = true, HelpText = "New name for the property")]
91+
public string NewName { get; set; }
92+
93+
public RenameCommand()
94+
{
95+
OldName = "";
96+
NewName = "";
97+
}
98+
}
99+
85100
[Verb("list", HelpText = "List all existing properties in the Store.")]
86101
public class ListCommand: Command
87102
{
@@ -195,6 +210,16 @@ public void ModifyProperty(ModifyCommand cmd)
195210
store.Save();
196211
}
197212

213+
public void RenameProperty(RenameCommand cmd)
214+
{
215+
Logger.Log().Info("Renaming Property {0} to {1}", cmd.OldName, cmd.NewName);
216+
PropertyStore store = OpenStore(cmd);
217+
LukeBot.Config.Path oldPath = LukeBot.Config.Path.Parse(cmd.OldName);
218+
store.Copy(oldPath, LukeBot.Config.Path.Parse(cmd.NewName));
219+
store.Remove(oldPath);
220+
store.Save();
221+
}
222+
198223
public void ListProperties(ListCommand cmd)
199224
{
200225
Logger.Log().Info("List properties in store {0}", cmd.StoreDir);

Tools/propmgr/MainClass.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ private static void HandleModifyCommand(ModifyCommand cmd)
3030
mProcessor.ModifyProperty(cmd);
3131
}
3232

33+
private static void HandleRenameCommand(RenameCommand cmd)
34+
{
35+
mProcessor.RenameProperty(cmd);
36+
}
37+
3338
private static void HandleListCommand(ListCommand cmd)
3439
{
3540
mProcessor.ListProperties(cmd);
@@ -54,11 +59,12 @@ public static void Main(string[] args)
5459

5560
try
5661
{
57-
Parser.Default.ParseArguments<CreateCommand, AddCommand, RemoveCommand, ModifyCommand, ListCommand>(args)
62+
Parser.Default.ParseArguments<CreateCommand, AddCommand, RemoveCommand, ModifyCommand, RenameCommand, ListCommand>(args)
5863
.WithParsed<CreateCommand>(HandleCreateCommand)
5964
.WithParsed<AddCommand>(HandleAddCommand)
6065
.WithParsed<RemoveCommand>(HandleRemoveCommand)
6166
.WithParsed<ModifyCommand>(HandleModifyCommand)
67+
.WithParsed<RenameCommand>(HandleRenameCommand)
6268
.WithParsed<ListCommand>(HandleListCommand)
6369
.WithNotParsed(HandleParseError);
6470
}

0 commit comments

Comments
 (0)