comparison rust/src/main.rs @ 635:4424a8b30f9c rust

config crate wants everything to be lower case
author Matt Johnston <matt@ucc.asn.au>
date Sun, 22 Sep 2019 22:06:46 +0800
parents a5721c02d3ee
children a9f353f488d0
comparison
equal deleted inserted replaced
634:a5721c02d3ee 635:4424a8b30f9c
10 mod sensor; 10 mod sensor;
11 mod fridge; 11 mod fridge;
12 mod types; 12 mod types;
13 mod params; 13 mod params;
14 14
15 use crate::config::Config;
16 15
17 use riker::actors::*; 16 use riker::actors::*;
18 17
19 use structopt::StructOpt; 18 use structopt::StructOpt;
20 19
21 fn run(cf: Config, nowait: bool, testmode: bool) { 20 use types::TemplogError;
21
22 fn run(conf_file: &str, nowait: bool, testmode: bool) -> Result<(), TemplogError> {
23
24 let cf = config::Config::load(conf_file)?;
22 25
23 let sys = ActorSystem::new().unwrap(); 26 let sys = ActorSystem::new().unwrap();
24 let props = Props::new_args(params::ParamWaiter::new, cf.clone()); 27 let props = Props::new_args(params::ParamWaiter::new, cf.clone());
25 sys.actor_of(props, "paramwaiter").unwrap(); 28 sys.actor_of(props, "paramwaiter").unwrap();
26 29
32 sys.actor_of(props, "sensor").unwrap() 35 sys.actor_of(props, "sensor").unwrap()
33 }; 36 };
34 37
35 let props = Props::new_args(fridge::Fridge::new_actor, (cf.clone(), nowait)); 38 let props = Props::new_args(fridge::Fridge::new_actor, (cf.clone(), nowait));
36 sys.actor_of(props, "fridge").unwrap(); 39 sys.actor_of(props, "fridge").unwrap();
40 Ok(())
37 } 41 }
38 42
39 #[derive(Debug, StructOpt)] 43 #[derive(Debug, StructOpt)]
40 #[structopt(name = "Wort Temperature", about = "Matt Johnston 2019 [email protected]")] 44 #[structopt(name = "Wort Temperature", about = "Matt Johnston 2019 [email protected]")]
41 struct Opt { 45 struct Opt {
56 60
57 /// Skip initial fridge wait 61 /// Skip initial fridge wait
58 #[structopt(long)] 62 #[structopt(long)]
59 nowait: bool, 63 nowait: bool,
60 64
61 /// Print default config (customise in local.conf) 65 /// Print default config (customise in local.toml)
62 #[structopt(long)] 66 #[structopt(long)]
63 defconf: bool, 67 defconf: bool,
68
69 /// Config file
70 #[structopt(short = "c", long, default_value = "local.toml")]
71 config: String,
64 } 72 }
65 73
66 fn handle_args() -> Opt { 74 fn handle_args() -> Opt {
67 let args = Opt::from_args(); 75 let args = Opt::from_args();
68 76
69 if args.defconf { 77 if args.defconf {
70 println!("Default configuration:\n{}\n\n{}", 78 println!("Default configuration:\n{}\n\n{}",
71 "(custom options go in local.conf)", 79 "(custom options go in local.toml)",
72 config::Config::default_toml()); 80 config::Config::default_toml());
73 std::process::exit(0); 81 std::process::exit(0);
74 } 82 }
75 args 83 args
76 } 84 }
101 //env_logger::init().unwrap(); 109 //env_logger::init().unwrap();
102 110
103 info!("wort-templog"); 111 info!("wort-templog");
104 debug!("debug mode"); 112 debug!("debug mode");
105 113
106 let config = config::Config::load().unwrap(); 114 let r = run(&args.config, args.nowait, args.test);
107 115 if let Err(e) = r {
108 run(config, args.nowait, args.test); 116 println!("Error running: {}", e);
117 }
109 } 118 }