From d1ca341f9a702fd60be2bb4ecfd52e3c4e98cd2a Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Sat, 5 Jan 2019 20:22:36 -0500 Subject: [PATCH] parse citadel.channel command line option Option takes a string argument which identifies the channel which should be expected when mounting images. The channel name can optionally be followed by a colon and a hex encoded public key for the channel. --- libcitadel/src/cmdline.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libcitadel/src/cmdline.rs b/libcitadel/src/cmdline.rs index de5aec8..df610fe 100644 --- a/libcitadel/src/cmdline.rs +++ b/libcitadel/src/cmdline.rs @@ -60,6 +60,36 @@ impl CommandLine { CommandLine::var_exists("citadel.recovery") } + pub fn channel() -> Option<&'static str> { + CommandLine::get_value("citadel.channel") + } + + fn _channel() -> Option<(&'static str,Option<&'static str>)> { + if let Some(channel) = CommandLine::channel() { + let parts = channel.splitn(2, ":").collect::>(); + if parts.len() == 2 { + return Some((parts[0], Some(parts[1]))) + } + return Some((channel, None)); + } + None + + } + + pub fn channel_name() -> Option<&'static str> { + if let Some((name, _)) = CommandLine::_channel() { + return Some(name) + } + None + } + + pub fn channel_pubkey() -> Option<&'static str> { + if let Some((_, pubkey)) = CommandLine::_channel() { + return pubkey + } + None + } + pub fn verbose() -> bool { CommandLine::var_exists("citadel.verbose") }