appmgr: minor fixes

This commit is contained in:
Aiden McClelland
2021-06-17 11:57:11 -06:00
parent de96a54cc1
commit 8871c6eec4
8 changed files with 123 additions and 28 deletions

View File

@@ -1,3 +1,4 @@
use std::path::Path;
use std::time::Duration;
use embassy::context::{EitherContext, RpcContext};
@@ -14,9 +15,8 @@ fn status_fn(_: i32) -> StatusCode {
StatusCode::OK
}
async fn inner_main() -> Result<(), Error> {
simple_logging::log_to_stderr(log::LevelFilter::Info);
let rpc_ctx = RpcContext::init().await?;
async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> {
let rpc_ctx = RpcContext::init(cfg_path).await?;
if !rpc_ctx.db.exists(&<JsonPointer>::default()).await? {
rpc_ctx
.db
@@ -24,7 +24,12 @@ async fn inner_main() -> Result<(), Error> {
.await?;
}
let ctx = EitherContext::Rpc(rpc_ctx.clone());
let server = rpc_server!(embassy::main_api, ctx, status_fn);
let server = rpc_server!({
command: embassy::main_api,
context: ctx,
status: status_fn,
});
let status_ctx = rpc_ctx.clone();
let status_daemon = daemon(
move || {
@@ -70,8 +75,32 @@ async fn inner_main() -> Result<(), Error> {
}
fn main() {
let matches = clap::App::new("embassyd")
.arg(
clap::Arg::with_name("config")
.short("c")
.long("config")
.takes_value(true),
)
.arg(
clap::Arg::with_name("verbosity")
.short("v")
.multiple(true)
.takes_value(false),
)
.get_matches();
simple_logging::log_to_stderr(match matches.occurrences_of("verbosity") {
0 => log::LevelFilter::Off,
1 => log::LevelFilter::Error,
2 => log::LevelFilter::Warn,
3 => log::LevelFilter::Info,
4 => log::LevelFilter::Debug,
_ => log::LevelFilter::Trace,
});
let cfg_path = matches.value_of("config");
let rt = tokio::runtime::Runtime::new().expect("failed to initialize runtime");
match rt.block_on(inner_main()) {
match rt.block_on(inner_main(cfg_path)) {
Ok(_) => (),
Err(e) => {
drop(rt);