forgeFRENParcourir les dépôts

roneocratesroneo-clisrcreporter.rs

0518da6beb3fd562b82c5b5c2798b72e0d1591b2

At commit 0518da6

79 lines · 2.4 KiBRustRaw
  1. use roneo_core::{ActionEvent, Reporter};
  2. use crate::style;
  3. #[derive(Debug, Clone, Copy)]
  4. pub struct ConsoleReporter {
  5. pub quiet: bool,
  6. pub pretend: bool,
  7. }
  8. impl Reporter for ConsoleReporter {
  9. fn emit(&self, event: ActionEvent) {
  10. if self.quiet {
  11. if let ActionEvent::Conflict(path) = event {
  12. eprintln!(" {:>10} {}", style::red_bold("conflict"), path.display());
  13. }
  14. return;
  15. }
  16. let prefix = if self.pretend {
  17. format!("{} ", style::dim("[dry-run]"))
  18. } else {
  19. String::new()
  20. };
  21. match event {
  22. ActionEvent::Create(p) => {
  23. println!(
  24. " {prefix}{:>10} {}",
  25. style::green_bold("create"),
  26. p.display()
  27. );
  28. }
  29. ActionEvent::Overwrite(p) => {
  30. println!(
  31. " {prefix}{:>10} {}",
  32. style::yellow_bold("overwrite"),
  33. p.display()
  34. );
  35. }
  36. ActionEvent::Update(p) => {
  37. println!(
  38. " {prefix}{:>10} {}",
  39. style::cyan_bold("update"),
  40. p.display()
  41. );
  42. }
  43. ActionEvent::Delete(p) => {
  44. println!(
  45. " {prefix}{:>10} {}",
  46. style::red_bold("delete"),
  47. p.display()
  48. );
  49. }
  50. ActionEvent::Identical(p) => {
  51. println!(" {prefix}{:>10} {}", style::dim("identical"), p.display());
  52. }
  53. ActionEvent::Skip(p) => {
  54. println!(" {prefix}{:>10} {}", style::blue("skip"), p.display());
  55. }
  56. ActionEvent::Conflict(p) => {
  57. eprintln!(
  58. " {prefix}{:>10} {}",
  59. style::red_bold("conflict"),
  60. p.display()
  61. );
  62. }
  63. ActionEvent::RunTask(cmd) => {
  64. println!(" {prefix}{:>10} {}", style::magenta_bold("run"), cmd);
  65. }
  66. ActionEvent::Message(msg) => {
  67. println!("\n{msg}\n");
  68. }
  69. ActionEvent::Warning(warn) => {
  70. eprintln!(" {:>10} {}", style::yellow_bold("warning"), warn);
  71. }
  72. }
  73. }
  74. }