Set.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. namespace TodoList
  7. {
  8. [Command(
  9. Name: "set",
  10. ShortDescription: "Set priority of a todo task.",
  11. ErrorText: "",
  12. LongHelpText: "Sets the priority of a todo task. Priority range is [0,FF]. Higher values mean higher priority."
  13. )]
  14. internal class Set : ICommand
  15. {
  16. [SwitchDocumentation("The ID of the task to prioritize.")]
  17. [DefaultSwitch(0)] public UInt32 id = 0;
  18. [DefaultSwitch(1)] public UInt32 priority = 0;
  19. [SwitchDocumentation("Path to task file.")]
  20. public string file = "todo.txt";
  21. public void Invoke(Dictionary<String, Object> PipedArguments)
  22. {
  23. if (String.IsNullOrEmpty(file))
  24. {
  25. Console.WriteLine("No file specified. How did you manage that? It defaults to todo.txt");
  26. return;
  27. }
  28. if (id == 0)
  29. {
  30. Console.WriteLine("You need to specify the entry you're editing.");
  31. return;
  32. }
  33. if (priority < 0 || priority > 0xFF)
  34. {
  35. Console.WriteLine("Valid range for option priority is [0,FF]");
  36. return;
  37. }
  38. var list = EntryList.LoadFile(file, true);
  39. var entry = list.Root.FindChildWithID(id);
  40. if (entry == null)
  41. {
  42. Console.WriteLine("Could not find entry with ID{0}.", id);
  43. return;
  44. }
  45. entry.Priority = priority;
  46. EntryList.SaveFile(file, list);
  47. Presentation.OutputEntry(entry, null, 0);
  48. }
  49. }
  50. }