Note.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: "note",
  10. ShortDescription: "Manage notes.",
  11. ErrorText: "",
  12. LongHelpText: "Adds notes to a task. Pass -r to remove all notes instead."
  13. )]
  14. internal class Note : ICommand
  15. {
  16. [SwitchDocumentation("The ID of the task to anotate.")]
  17. [DefaultSwitch(0)] public UInt32 id = 0;
  18. [DefaultSwitch(1), GreedyArgument] public String note = "";
  19. public bool r = false;
  20. [SwitchDocumentation("Path to task file.")]
  21. public string file = "todo.txt";
  22. public void Invoke(Dictionary<String, Object> PipedArguments)
  23. {
  24. if (String.IsNullOrEmpty(file))
  25. {
  26. Console.WriteLine("No file specified. How did you manage that? It defaults to todo.txt");
  27. return;
  28. }
  29. if (id == 0)
  30. {
  31. Console.WriteLine("You need to specify the entry you're editing.");
  32. return;
  33. }
  34. var list = EntryList.LoadFile(file, true);
  35. var entry = list.Root.FindChildWithID(id);
  36. if (entry == null)
  37. {
  38. Console.WriteLine("Could not find entry with ID{0}.", id);
  39. return;
  40. }
  41. if (r)
  42. entry.Notes = "";
  43. else
  44. {
  45. if (String.IsNullOrEmpty(note))
  46. {
  47. Console.WriteLine("You need to supply a note.");
  48. return;
  49. }
  50. if (!String.IsNullOrEmpty(entry.Notes))
  51. entry.Notes += "\n";
  52. entry.Notes += note;
  53. }
  54. EntryList.SaveFile(file, list);
  55. Presentation.OutputEntryDetails(entry);
  56. }
  57. }
  58. }