Skip to content

Commit

Permalink
Merge pull request #219 from epage/types
Browse files Browse the repository at this point in the history
feat(config): Per-file type settings
  • Loading branch information
epage authored Apr 6, 2021
2 parents a148054 + aa21439 commit 0656a62
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 320 deletions.
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Configuration is read from the following (in precedence order)
| default.locale | --locale | en, en-us, en-gb, en-ca, en-au | English dialect to correct to. |
| default.extend-identifiers | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
| default.extend-words | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
| type.<name>.binary | <varied> | <varied> | See `default.` for child keys. Run with `--type-list` to see available `<name>`s |
55 changes: 38 additions & 17 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ pub(crate) struct Args {
/// Write the current configuration to file with `-` for stdout
pub(crate) dump_config: Option<std::path::PathBuf>,

#[structopt(flatten)]
pub(crate) overrides: FileArgs,
#[structopt(long, group = "mode")]
/// Show all supported file types.
pub(crate) type_list: bool,

#[structopt(
long,
Expand Down Expand Up @@ -129,7 +130,20 @@ 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()
}),
}
}

fn binary(&self) -> Option<bool> {
match (self.binary, self.no_binary) {
(true, false) => Some(true),
Expand All @@ -156,28 +170,24 @@ 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)]
#[structopt(rename_all = "kebab-case")]
pub(crate) struct ConfigArgs {
#[structopt(flatten)]
walk: WalkArgs,
#[structopt(flatten)]
overrides: FileArgs,
}

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(),
overrides: self.overrides.to_config(),
..Default::default()
}
}
}

Expand Down Expand Up @@ -221,7 +231,18 @@ 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(),
}
}

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

0 comments on commit 0656a62

Please sign in to comment.