summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-06-20 09:25:57 +0300
committerLars Wirzenius <liw@liw.fi>2021-07-05 16:15:59 +0300
commit79c71be291b3cf1fad52e2fbdc28be12d3e11311 (patch)
tree693a02358e5a50ffd193ed96d1f9307c75256b39 /src/bin
parente1730c4b1e10fa1c6530a55e25824a44d82e2cc0 (diff)
downloadobnam2-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.rs19
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(())