diff options
Diffstat (limited to 'nitrocli/src/error.rs')
-rw-r--r-- | nitrocli/src/error.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/nitrocli/src/error.rs b/nitrocli/src/error.rs index 819bed8..f613100 100644 --- a/nitrocli/src/error.rs +++ b/nitrocli/src/error.rs @@ -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)?; |