chiark / gitweb /
print config value
[hippotat.git] / server / server.rs
index 02af6f8292142901baf1be6765a3e99fccc7087c..05796d06bf5bde08a481e7a8e1ec74b649b82ee6 100644 (file)
@@ -24,6 +24,10 @@ pub struct Opts {
   /// Daemonise
   #[structopt(long)]
   daemon: bool,
+
+  /// Print a config item, do not actually run
+  #[structopt(long)]
+  print_config: Option<String>,
 }
 
 pub const METADATA_MAX_LEN: usize = MAX_OVERHEAD;
@@ -123,7 +127,7 @@ pub async fn route_packet(global: &Global,
 
 fn main() {
   let opts = Opts::from_args();
-  let daemon = if opts.daemon {
+  let daemon = if opts.daemon && opts.print_config.is_none() {
     Some(Daemoniser::phase1())
   } else {
     None
@@ -145,6 +149,15 @@ async fn async_main(opts: Opts, daemon: Option<Daemoniser>) {
   {
     let global_config = config::InstanceConfigGlobal::from(&ics);
 
+    if let Some(key) = opts.print_config.as_ref() {
+      if let Some(inspectable) = global_config.inspect_key(key) {
+        println!("{}", DisplayInspectable(inspectable));
+        process::exit(0);
+      } else {
+        throw!(anyhow!("unknown config key {:?}", key));
+      }
+    }
+
     let ipif = Ipif::start(&global_config.ipif, None)?;
 
     let ics = ics.into_iter().map(Arc::new).collect_vec();