diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/error.rs b/src/error.rs index 819bed8..3e458a6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ // error.rs // ************************************************************************* -// * Copyright (C) 2017-2019 Daniel Mueller (deso@posteo.net) * +// * Copyright (C) 2017-2020 Daniel Mueller (deso@posteo.net) * // * * // * This program is free software: you can redistribute it and/or modify * // * it under the terms of the GNU General Public License as published by * @@ -22,6 +22,8 @@ use std::io; use std::str; use std::string; +use structopt::clap; + /// A trait used to simplify error handling in conjunction with the /// try_with_* functions we use for repeatedly asking the user for a /// secret. @@ -40,7 +42,7 @@ where #[derive(Debug)] pub enum Error { - ArgparseError(i32), + ClapError(clap::Error), IoError(io::Error), NitrokeyError(Option<&'static str>, nitrokey::Error), Utf8Error(str::Utf8Error), @@ -62,6 +64,12 @@ impl From<&str> for Error { } } +impl From<clap::Error> for Error { + fn from(e: clap::Error) -> Error { + Error::ClapError(e) + } +} + impl From<nitrokey::Error> for Error { fn from(e: nitrokey::Error) -> Error { Error::NitrokeyError(None, e) @@ -89,7 +97,7 @@ impl From<string::FromUtf8Error> for Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - Error::ArgparseError(_) => write!(f, "Could not parse arguments"), + Error::ClapError(ref e) => write!(f, "{}", e), Error::NitrokeyError(ref ctx, ref e) => { if let Some(ctx) = ctx { write!(f, "{}: ", ctx)?; |