Skip to content

Commit

Permalink
refactor(cli): Drop the traits from layering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Apr 1, 2021
1 parent 13617fa commit 78330ba
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 261 deletions.
49 changes: 34 additions & 15 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,21 @@ pub(crate) struct FileArgs {
pub(crate) locale: Option<config::Locale>,
}

impl config::EngineSource for FileArgs {
impl FileArgs {
pub fn to_config(&self) -> config::EngineConfig {
config::EngineConfig {
binary: self.binary(),
check_filename: self.check_filename(),
check_file: self.check_file(),
tokenizer: None,
dict: Some(config::DictConfig {
locale: self.locale,
..Default::default()
}),
..Default::default()
}
}

fn binary(&self) -> Option<bool> {
match (self.binary, self.no_binary) {
(true, false) => Some(true),
Expand All @@ -156,16 +170,6 @@ impl config::EngineSource for FileArgs {
(_, _) => unreachable!("StructOpt should make this impossible"),
}
}

fn dict(&self) -> Option<&dyn config::DictSource> {
Some(self)
}
}

impl config::DictSource for FileArgs {
fn locale(&self) -> Option<config::Locale> {
self.locale
}
}

#[derive(Debug, StructOpt)]
Expand All @@ -175,9 +179,12 @@ pub(crate) struct ConfigArgs {
walk: WalkArgs,
}

impl config::ConfigSource for ConfigArgs {
fn walk(&self) -> Option<&dyn config::WalkSource> {
Some(&self.walk)
impl ConfigArgs {
pub fn to_config(&self) -> config::Config {
config::Config {
files: self.walk.to_config(),
..Default::default()
}
}
}

Expand Down Expand Up @@ -221,7 +228,19 @@ pub(crate) struct WalkArgs {
ignore_vcs: bool,
}

impl config::WalkSource for WalkArgs {
impl WalkArgs {
pub fn to_config(&self) -> config::Walk {
config::Walk {
ignore_hidden: self.ignore_hidden(),
ignore_files: self.ignore_files(),
ignore_dot: self.ignore_dot(),
ignore_vcs: self.ignore_vcs(),
ignore_global: self.ignore_global(),
ignore_parent: self.ignore_parent(),
..Default::default()
}
}

fn ignore_hidden(&self) -> Option<bool> {
match (self.hidden, self.no_hidden) {
(true, false) => Some(false),
Expand Down
Loading

0 comments on commit 78330ba

Please sign in to comment.