2019-08-29 14:46:54 -07:00
|
|
|
//! `start` subcommand - example of how to write a subcommand
|
|
|
|
|
|
|
|
/// App-local prelude includes `app_reader()`/`app_writer()`/`app_config()`
|
|
|
|
/// accessors along with logging macros. Customize as you see fit.
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
use crate::config::ZebradConfig;
|
2019-12-13 14:25:14 -08:00
|
|
|
|
2019-08-29 14:46:54 -07:00
|
|
|
use abscissa_core::{config, Command, FrameworkError, Options, Runnable};
|
|
|
|
|
2019-12-13 14:25:14 -08:00
|
|
|
use futures::prelude::*;
|
|
|
|
|
2019-08-29 14:46:54 -07:00
|
|
|
/// `start` subcommand
|
|
|
|
///
|
|
|
|
/// The `Options` proc macro generates an option parser based on the struct
|
|
|
|
/// definition, and is defined in the `gumdrop` crate. See their documentation
|
|
|
|
/// for a more comprehensive example:
|
|
|
|
///
|
|
|
|
/// <https://docs.rs/gumdrop/>
|
|
|
|
#[derive(Command, Debug, Options)]
|
|
|
|
pub struct StartCmd {
|
2019-09-09 13:05:42 -07:00
|
|
|
/// Filter strings
|
2019-08-29 14:46:54 -07:00
|
|
|
#[options(free)]
|
2019-09-09 13:05:42 -07:00
|
|
|
filters: Vec<String>,
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Runnable for StartCmd {
|
|
|
|
/// Start the application.
|
|
|
|
fn run(&self) {
|
2019-09-09 13:05:42 -07:00
|
|
|
warn!("starting application");
|
2019-08-29 14:46:54 -07:00
|
|
|
let config = app_config();
|
2019-09-09 13:05:42 -07:00
|
|
|
println!("filter: {}!", &config.tracing.filter);
|
|
|
|
|
|
|
|
let default_config = ZebradConfig::default();
|
|
|
|
println!("Default config: {:?}", default_config);
|
|
|
|
|
|
|
|
println!("Toml:\n{}", toml::to_string(&default_config).unwrap());
|
|
|
|
|
|
|
|
info!("Starting placeholder loop");
|
|
|
|
|
|
|
|
use crate::components::tokio::TokioComponent;
|
|
|
|
|
2019-12-13 14:25:14 -08:00
|
|
|
app_writer()
|
|
|
|
.state_mut()
|
2019-09-09 13:05:42 -07:00
|
|
|
.components
|
2019-12-13 14:25:14 -08:00
|
|
|
.get_downcast_mut::<TokioComponent>()
|
2019-09-09 13:05:42 -07:00
|
|
|
.expect("TokioComponent should be available")
|
|
|
|
.rt
|
2019-12-13 14:25:14 -08:00
|
|
|
.block_on(future::pending::<()>());
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl config::Override<ZebradConfig> for StartCmd {
|
|
|
|
// Process the given command line options, overriding settings from
|
|
|
|
// a configuration file using explicit flags taken from command-line
|
|
|
|
// arguments.
|
2019-09-09 13:05:42 -07:00
|
|
|
fn override_config(&self, mut config: ZebradConfig) -> Result<ZebradConfig, FrameworkError> {
|
|
|
|
if !self.filters.is_empty() {
|
|
|
|
config.tracing.filter = self.filters.join(",");
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(config)
|
|
|
|
}
|
|
|
|
}
|