diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-06-20 09:25:57 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-05 16:15:59 +0300 |
commit | 79c71be291b3cf1fad52e2fbdc28be12d3e11311 (patch) | |
tree | 693a02358e5a50ffd193ed96d1f9307c75256b39 /src/bin | |
parent | e1730c4b1e10fa1c6530a55e25824a44d82e2cc0 (diff) | |
download | obnam2-79c71be291b3cf1fad52e2fbdc28be12d3e11311.tar.gz |
refactor: have main explicitly print error message
This is a little cleaner than having main print an error message by
returning an Err value as a Result. For one thing, we can be more sure
we log the error.
Sponsored-by: author
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/obnam.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs index c8da6c2..9739501 100644 --- a/src/bin/obnam.rs +++ b/src/bin/obnam.rs @@ -19,7 +19,15 @@ const QUALIFIER: &str = ""; const ORG: &str = ""; const APPLICATION: &str = "obnam"; -fn main() -> anyhow::Result<()> { +fn main() { + if let Err(err) = main_program() { + error!("{}", err); + eprintln!("ERROR: {}", err); + std::process::exit(1); + } +} + +fn main_program() -> anyhow::Result<()> { let opt = Opt::from_args(); let config = ClientConfig::read(&config_filename(&opt))?; setup_logging(&config.log)?; @@ -28,7 +36,7 @@ fn main() -> anyhow::Result<()> { debug!("{:?}", opt); debug!("configuration: {:#?}", config); - let result = match opt.cmd { + match opt.cmd { Command::Init(x) => x.run(&config), Command::Backup(x) => x.run(&config), Command::List(x) => x.run(&config), @@ -39,12 +47,7 @@ fn main() -> anyhow::Result<()> { Command::Config(x) => x.run(&config), Command::EncryptChunk(x) => x.run(&config), Command::DecryptChunk(x) => x.run(&config), - }; - - if let Err(ref e) = result { - error!("command failed: {}", e); - result? - } + }?; info!("client ends successfully"); Ok(()) |