repotype.rs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. use serde::{Deserialize, Serialize};
  2. use std::fmt;
  3. use crate::lib::config::Config;
  4. #[derive(Serialize, Deserialize)]
  5. pub struct RepoType {
  6. #[serde(default)]
  7. name: String,
  8. #[serde(default)]
  9. description: String,
  10. #[serde(default)]
  11. create: String,
  12. #[serde(default)]
  13. inward: String,
  14. #[serde(default)]
  15. outward: String,
  16. #[serde(default)]
  17. status: String,
  18. #[serde(default)]
  19. pre_inward: String,
  20. #[serde(default)]
  21. post_inward: String,
  22. #[serde(default)]
  23. post_outward: String,
  24. }
  25. pub fn add(config: &mut Config, name: &String, description: &String, create: &String, inward: &String, outward: &String, status: &String, pre_inward: &String, post_inward: &String, post_outward: &String) {
  26. let repo_type = RepoType {
  27. name: name.to_string(),
  28. description: description.to_string(),
  29. create: create.to_string(),
  30. inward: inward.to_string(),
  31. outward: outward.to_string(),
  32. status: status.to_string(),
  33. pre_inward: pre_inward.to_string(),
  34. post_inward: post_inward.to_string(),
  35. post_outward: post_outward.to_string()
  36. };
  37. config.repo_types.insert(name.to_string(), repo_type);
  38. }
  39. pub fn update_description(config: &mut Config, name: &String, description: &String) {
  40. match config.repo_types.get_mut(&name.to_string()) {
  41. Some(repo_type) => repo_type.description = description.to_string(),
  42. None => panic!("No known repository type named \"{}\".", name)
  43. }
  44. }
  45. pub fn update_create(config: &mut Config, name: &String, create: &String) {
  46. match config.repo_types.get_mut(&name.to_string()) {
  47. Some(repo_type) => repo_type.create = create.to_string(),
  48. None => panic!("No known repository type named \"{}\".", name)
  49. }
  50. }
  51. pub fn update_inward(config: &mut Config, name: &String, inward: &String) {
  52. match config.repo_types.get_mut(&name.to_string()) {
  53. Some(repo_type) => repo_type.inward = inward.to_string(),
  54. None => panic!("No known repository type named \"{}\".", name)
  55. }
  56. }
  57. pub fn update_outward(config: &mut Config, name: &String, outward: &String) {
  58. match config.repo_types.get_mut(&name.to_string()) {
  59. Some(repo_type) => repo_type.outward = outward.to_string(),
  60. None => panic!("No known repository type named \"{}\".", name)
  61. }
  62. }
  63. pub fn update_status(config: &mut Config, name: &String, status: &String) {
  64. match config.repo_types.get_mut(&name.to_string()) {
  65. Some(repo_type) => repo_type.status = status.to_string(),
  66. None => panic!("No known repository type named \"{}\".", name)
  67. }
  68. }
  69. pub fn update_pre_inward(config: &mut Config, name: &String, pre_inward: &String) {
  70. match config.repo_types.get_mut(&name.to_string()) {
  71. Some(repo_type) => repo_type.pre_inward = pre_inward.to_string(),
  72. None => panic!("No known repository type named \"{}\".", name)
  73. }
  74. }
  75. pub fn update_post_inward(config: &mut Config, name: &String, post_inward: &String) {
  76. match config.repo_types.get_mut(&name.to_string()) {
  77. Some(repo_type) => repo_type.post_inward = post_inward.to_string(),
  78. None => panic!("No known repository type named \"{}\".", name)
  79. }
  80. }
  81. pub fn update_post_outward(config: &mut Config, name: &String, post_outward: &String) {
  82. match config.repo_types.get_mut(&name.to_string()) {
  83. Some(repo_type) => repo_type.post_outward = post_outward.to_string(),
  84. None => panic!("No known repository type named \"{}\".", name)
  85. }
  86. }
  87. impl fmt::Display for RepoType {
  88. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  89. write!(f, "Repository type {}:\n\t\"{}\"\n\tCreation Command: {}\n\tInward Sync: {}\n\tOutward Sync: {}\n\tStatus: {}\n\tPre-inward: {}\n\tPost-inward: {}\n\tPost-outward: {}",
  90. self.name,
  91. self.description,
  92. self.create,
  93. self.inward,
  94. self.outward,
  95. self.status,
  96. self.pre_inward,
  97. self.post_inward,
  98. self.post_outward)
  99. }
  100. }