lighthouse/watch/src/cli.rs
Jimmy Chen b0c374c1ca
Update dependencies to get rid of the yanked deps (#4994)
* Initial attempt to upgrade hashbrown to latest to get rid of the crate warnings.

* Replace `.expect()` usage with use of `const`.

* Update ahash 0.7 as well

* Remove unsafe code.

* Update `lru` to 0.12 and fix release test errors.

* Set non-blocking socket

* Bump testcontainers to 0.15.

* Fix lint

---------

Co-authored-by: Michael Sproul <michael@sigmaprime.io>
2023-12-15 18:31:59 +11:00

52 lines
1.5 KiB
Rust

use crate::{config::Config, logger, server, updater};
use clap::{App, Arg};
pub const SERVE: &str = "serve";
pub const RUN_UPDATER: &str = "run-updater";
pub const CONFIG: &str = "config";
fn run_updater<'a, 'b>() -> App<'a, 'b> {
App::new(RUN_UPDATER).setting(clap::AppSettings::ColoredHelp)
}
fn serve<'a, 'b>() -> App<'a, 'b> {
App::new(SERVE).setting(clap::AppSettings::ColoredHelp)
}
pub fn app<'a, 'b>() -> App<'a, 'b> {
App::new("beacon_watch_daemon")
.author("Sigma Prime <contact@sigmaprime.io>")
.setting(clap::AppSettings::ColoredHelp)
.arg(
Arg::with_name(CONFIG)
.long(CONFIG)
.value_name("PATH_TO_CONFIG")
.help("Path to configuration file")
.takes_value(true)
.global(true),
)
.subcommand(run_updater())
.subcommand(serve())
}
pub async fn run() -> Result<(), String> {
let matches = app().get_matches();
let config = match matches.value_of(CONFIG) {
Some(path) => Config::load_from_file(path.to_string())?,
None => Config::default(),
};
logger::init_logger(&config.log_level);
match matches.subcommand() {
(RUN_UPDATER, Some(_)) => updater::run_updater(config)
.await
.map_err(|e| format!("Failure: {:?}", e)),
(SERVE, Some(_)) => server::serve(config)
.await
.map_err(|e| format!("Failure: {:?}", e)),
_ => Err("Unsupported subcommand. See --help".into()),
}
}