Complete.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: "complete",
  10. ShortDescription: "Marks a todo task as complete.",
  11. ErrorText: "",
  12. LongHelpText: "Change the status of a todo task to complete. This will hide the task from the list command unless -all is passed to list. It also causes the task to display in blue.",
  13. Synonyms: "done mark"
  14. )]
  15. internal class Complete : ICommand
  16. {
  17. [SwitchDocumentation("The ID of the task to mark complete.")]
  18. [DefaultSwitch(0)] public UInt32 id = 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. var list = EntryList.LoadFile(file, true);
  34. var entry = list.Root.FindChildWithID(id);
  35. if (entry == null)
  36. {
  37. Console.WriteLine("Could not find entry with ID{0}.", id);
  38. return;
  39. }
  40. foreach (var pre in entry.Preregs)
  41. {
  42. var check = list.Root.FindChildWithID(pre);
  43. if (check != null && check.Status != "✓")
  44. {
  45. Console.WriteLine("Could not mark this item complete as prereg {0:X4} is not complete.", pre);
  46. return;
  47. }
  48. }
  49. entry.Status = "✓";
  50. entry.CompletionTime = DateTime.Now;
  51. EntryList.SaveFile(file, list);
  52. Presentation.OutputEntry(entry, null, 0);
  53. }
  54. }
  55. }