list.rs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // imag - the personal information management suite for the commandline
  3. // Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
  4. //
  5. // This library is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; version
  8. // 2.1 of the License.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public
  16. // License along with this library; if not, write to the Free Software
  17. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. //
  19. use libimagrt::runtime::Runtime;
  20. use libimagerror::trace::{MapErrTrace, trace_error};
  21. use libimagcounter::counter::Counter;
  22. pub fn list(rt: &Runtime) {
  23. rt.cli()
  24. .subcommand_matches("list")
  25. .map(|_| {
  26. debug!("Found 'list' subcommand...");
  27. Counter::all_counters(rt.store()).map(|iterator| {
  28. for counter in iterator {
  29. counter.map(|c| {
  30. let name = c.name();
  31. let value = c.value();
  32. let unit = c.unit();
  33. if name.is_err() {
  34. trace_error(&name.unwrap_err());
  35. } else if value.is_err() {
  36. trace_error(&value.unwrap_err());
  37. } else if unit.is_none() {
  38. println!("{} - {}", name.unwrap(), value.unwrap());
  39. } else {
  40. println!("{} - {} {}", name.unwrap(), value.unwrap(), unit.unwrap());
  41. }
  42. })
  43. .map_err_trace()
  44. .ok();
  45. }
  46. })
  47. .map_err_trace()
  48. });
  49. }