Skip to content

Commit

Permalink
Remove dependency on crate::Error from arg_defs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
d-e-s-o committed Apr 4, 2020
1 parent eab4b20 commit 83d3e90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/arg_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use crate::args;
use crate::commands;
use crate::error::Error;

/// Provides access to a Nitrokey device
#[derive(structopt::StructOpt)]
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 83d3e90

Please sign in to comment.