summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-04-04 10:38:24 -0700
committerDaniel Mueller <deso@posteo.net>2020-04-04 10:38:24 -0700
commit83d3e90248e9995e6c37c314b10597bccd394341 (patch)
tree04d9f5be863fcbc71461934b49aab198da04a482 /src
parenteab4b20d16760043a1ec4d80d2e239fc1559bb2f (diff)
downloadnitrocli-83d3e90248e9995e6c37c314b10597bccd394341.tar.gz
nitrocli-83d3e90248e9995e6c37c314b10597bccd394341.tar.bz2
Remove dependency on crate::Error from arg_defs
This change removes the need to import crate::Error from the arg_defs module. By dropping this dependency we make the file more independent of the rest of the crate, which subsequently will allow us to merely include! it in another file in order to get the argument related type definitions without compilation errors due to missing symbols from the rest of the crate.
Diffstat (limited to 'src')
-rw-r--r--src/arg_defs.rs7
-rw-r--r--src/error.rs6
2 files changed, 9 insertions, 4 deletions
diff --git a/src/arg_defs.rs b/src/arg_defs.rs
index 0172a81..c58d230 100644
--- a/src/arg_defs.rs
+++ b/src/arg_defs.rs
@@ -19,7 +19,6 @@
use crate::args;
use crate::commands;
-use crate::error::Error;
/// Provides access to a Nitrokey device
#[derive(structopt::StructOpt)]
@@ -136,13 +135,13 @@ pub enum ConfigOption<T> {
}
impl<T> ConfigOption<T> {
- pub fn try_from(disable: bool, value: Option<T>, name: &'static str) -> Result<Self, Error> {
+ pub fn try_from(disable: bool, value: Option<T>, name: &'static str) -> Result<Self, String> {
if disable {
if value.is_some() {
- Err(Error::Error(format!(
+ Err(format!(
"--{name} and --no-{name} are mutually exclusive",
name = name
- )))
+ ))
} else {
Ok(ConfigOption::Disable)
}
diff --git a/src/error.rs b/src/error.rs
index 3e458a6..e891da2 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -64,6 +64,12 @@ impl From<&str> for Error {
}
}
+impl From<String> for Error {
+ fn from(s: String) -> Error {
+ Error::Error(s)
+ }
+}
+
impl From<clap::Error> for Error {
fn from(e: clap::Error) -> Error {
Error::ClapError(e)