options.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use clap::{App, Arg, ArgMatches};
  2. use darkfi::Result;
  3. pub struct ProgramOptions {
  4. pub log_path: Box<std::path::PathBuf>,
  5. pub app: ArgMatches,
  6. }
  7. impl ProgramOptions {
  8. pub fn load() -> Result<ProgramOptions> {
  9. let app = App::new("dnetview")
  10. .version("0.1.0")
  11. .author("lunar_mining")
  12. .about("dnetview")
  13. .arg(
  14. Arg::new("LOG_PATH")
  15. .long("log")
  16. .value_name("LOG_PATH")
  17. .help("Logfile path")
  18. .takes_value(true),
  19. )
  20. .arg(
  21. Arg::new("verbose")
  22. .short('v')
  23. .long("verbose")
  24. .multiple_occurrences(true)
  25. .help("Sets the level of verbosity"),
  26. )
  27. .get_matches();
  28. let log_path = Box::new(
  29. if let Some(log_path) = app.value_of("LOG_PATH") {
  30. std::path::Path::new(log_path)
  31. } else {
  32. std::path::Path::new("/tmp/dnetview.log")
  33. }
  34. .to_path_buf(),
  35. );
  36. Ok(ProgramOptions { log_path, app })
  37. }
  38. }