From: Ian Jackson Date: Wed, 4 Aug 2021 23:22:36 +0000 (+0100) Subject: wip server X-Git-Tag: hippotat/1.0.0~329 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=11b2beefc8bb44d49308c7a56cf188f5bef80ec7;p=hippotat.git wip server Signed-off-by: Ian Jackson --- diff --git a/Cargo.toml b/Cargo.toml index dbc8285..1212275 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,10 @@ members = ["macros"] name="hippotat" path="src/bin/client.rs" +[[bin]] +name="hippotatd" +path="src/bin/server.rs" + [dependencies] hippotat-macros = { path = "macros" } diff --git a/src/bin/client.rs b/src/bin/client.rs index 8bd8013..74b1d4b 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -9,9 +9,8 @@ const MAX_BATCH_DOWN_RESP_OVERHEAD: usize = 10_000; #[derive(StructOpt,Debug)] pub struct Opts { - /// Increase debug level - #[structopt(long, short="D", parse(from_occurrences))] - debug: usize, + #[structopt(flatten)] + log: LogOpts, #[structopt(flatten)] config: config::Opts, @@ -319,22 +318,7 @@ async fn main() -> Result<(), AE> { let ics = config::read(&opts.config, LinkEnd::Client)?; if ics.is_empty() { throw!(anyhow!("no associations with server(s)")); } - { - let env = env_logger::Env::new() - .filter("HIPPOTAT_LOG") - .write_style("HIPPOTAT_LOG_STYLE"); - - let mut logb = env_logger::Builder::new(); - logb.filter(Some("hippotat"), - *[ log::LevelFilter::Info, - log::LevelFilter::Debug ] - .get(opts.debug) - .unwrap_or( - &log::LevelFilter::Trace - )); - logb.parse_env(env); - logb.init(); - } + opts.log.log_init()?; let https = HttpsConnector::new(); let hclient = hyper::Client::builder().build::<_, hyper::Body>(https); diff --git a/src/bin/server.rs b/src/bin/server.rs new file mode 100644 index 0000000..d97cf1c --- /dev/null +++ b/src/bin/server.rs @@ -0,0 +1,27 @@ +// Copyright 2021 Ian Jackson and contributors to Hippotat +// SPDX-License-Identifier: GPL-3.0-or-later +// There is NO WARRANTY. + +use hippotat::prelude::*; + +#[derive(StructOpt,Debug)] +pub struct Opts { + #[structopt(flatten)] + log: LogOpts, + + #[structopt(flatten)] + config: config::Opts, +} + +#[tokio::main] +async fn main() -> Result<(), AE> { + let opts = Opts::from_args(); + + let ics = config::read(&opts.config, LinkEnd::Server)?; + + opts.log.log_init()?; + + dbg!(ics); + + Ok(()) +} diff --git a/src/reporter.rs b/src/reporter.rs index 24cd6b8..0d199ec 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -4,6 +4,33 @@ use crate::prelude::*; +#[derive(StructOpt,Debug)] +pub struct LogOpts { + /// Increase debug level + #[structopt(long, short="D", parse(from_occurrences))] + debug: usize, +} + +impl LogOpts { + #[throws(AE)] + pub fn log_init(&self) { + let env = env_logger::Env::new() + .filter("HIPPOTAT_LOG") + .write_style("HIPPOTAT_LOG_STYLE"); + + let mut logb = env_logger::Builder::new(); + logb.filter(Some("hippotat"), + *[ log::LevelFilter::Info, + log::LevelFilter::Debug ] + .get(self.debug) + .unwrap_or( + &log::LevelFilter::Trace + )); + logb.parse_env(env); + logb.init(); + } +} + // For clients only, really. pub struct Reporter<'r> { ic: &'r InstanceConfig,