You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.rs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //#![allow(unused)]
  2. #![allow(incomplete_features)]
  3. #![feature(impl_trait_in_bindings)]
  4. #![feature(async_closure)]
  5. mod config;
  6. mod spool;
  7. use std::path::PathBuf;
  8. use clap::Clap;
  9. use tokio::{self, runtime};
  10. use crate::config::*;
  11. #[derive(Clap)]
  12. #[clap(version = "0.1")]
  13. struct Opts {
  14. #[clap(
  15. name = "config",
  16. short = "c",
  17. help = "Read this config file by itself, parsed before -C"
  18. )]
  19. conf: Option<PathBuf>,
  20. #[clap(
  21. name = "configdir",
  22. short = "C",
  23. help = "Read all config files in this directory"
  24. )]
  25. conf_dir: Option<PathBuf>,
  26. #[clap(
  27. name = "triggerpath",
  28. short = "r",
  29. help = "Delete this file to trigger a config reload [NYI]"
  30. )]
  31. reload_trigger: Option<PathBuf>,
  32. }
  33. fn main() {
  34. let opts = Opts::parse();
  35. if opts.reload_trigger.is_some() {
  36. println!("Reload trigger file specified, but this option is not supported yet. Ignoring.");
  37. }
  38. let mut rt = make_runtime();
  39. // Figure out which files we want to configure.
  40. let mut confs = Vec::new();
  41. if let Some(main) = opts.conf {
  42. confs.push(main.clone());
  43. }
  44. if let Some(dir) = opts.conf_dir {
  45. match rt.block_on(find_configs(&dir)) {
  46. Ok(paths) => confs.extend(paths),
  47. Err(e) => {
  48. println!("Error reading configuration: {:?}", e);
  49. return;
  50. }
  51. }
  52. }
  53. // Sanity check.
  54. if confs.len() == 0 {
  55. println!("No configuration declared, exiting...");
  56. return;
  57. }
  58. // Process configuration.
  59. let config = match rt.block_on(parse_configs(confs)) {
  60. Ok(c) => c,
  61. Err(e) => {
  62. println!("Error parsing configuration: {:?}", e);
  63. return; // maybe
  64. }
  65. };
  66. for s in &config.spool_dirs {
  67. if s.send_delay_sec != 0 {
  68. println!(
  69. "Warning: send delay (as in watch on {:?}) are current not supported, ignoring",
  70. s.path
  71. );
  72. }
  73. }
  74. // This is where the real stuff actually happens.
  75. match rt.block_on(spool::start_spooling(config)) {
  76. Ok(_) => {}
  77. Err(e) => println!("fatal error: {:?}", e),
  78. }
  79. }
  80. fn make_runtime() -> runtime::Runtime {
  81. runtime::Builder::new()
  82. .max_threads(1)
  83. .enable_all()
  84. .basic_scheduler()
  85. .build()
  86. .expect("init runtime")
  87. }