From 3295950f41342b8b9a312f203b111c7c277500b4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 10 Apr 2021 10:15:58 +0300 Subject: refactor: main function for clarity --- src/bin/obnam.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs index 4f4cd5b..cdb5179 100644 --- a/src/bin/obnam.rs +++ b/src/bin/obnam.rs @@ -27,19 +27,20 @@ fn main() -> anyhow::Result<()> { debug!("{:?}", opt); debug!("configuration: {:#?}", config); - let result = if let Command::Init(init) = opt.cmd { - init.run(config.config()) - } else { - let config = load_config_with_passwords(&opt)?; - match opt.cmd { - Command::Init(_) => panic!("this cannot happen"), - Command::Backup(x) => x.run(&config), - Command::List(x) => x.run(&config), - Command::ShowGeneration(x) => x.run(&config), - Command::ListFiles(x) => x.run(&config), - Command::Restore(x) => x.run(&config), - Command::GetChunk(x) => x.run(&config), - Command::Config(x) => x.run(&config), + let result = match opt.cmd { + Command::Init(x) => x.run(config.config()), + _ => { + let config = load_config_with_passwords(&opt)?; + match opt.cmd { + Command::Init(_) => panic!("this can't happen"), + Command::Backup(x) => x.run(&config), + Command::List(x) => x.run(&config), + Command::ShowGeneration(x) => x.run(&config), + Command::ListFiles(x) => x.run(&config), + Command::Restore(x) => x.run(&config), + Command::GetChunk(x) => x.run(&config), + Command::Config(x) => x.run(&config), + } } }; -- cgit v1.2.1