Skip to content

Commit

Permalink
feat: Accept config on command-line
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 8, 2019
1 parent 8d96a2a commit 3d4da68
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ regex = "1.0"
lazy_static = "1.2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.4"
itertools = "0.8"
unicase = "1.1"
bstr = "0.2"
Expand Down
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#[macro_use]
extern crate clap;

use std::io::Read;
use std::io::Write;

use structopt::StructOpt;
Expand Down Expand Up @@ -42,6 +43,10 @@ struct Options {
/// Paths to check
path: Vec<std::path::PathBuf>,

#[structopt(short = "c", long = "config")]
/// Custom config file
custom_config: Option<String>,

#[structopt(long, raw(overrides_with = r#""check-filenames""#))]
/// Skip verifying spelling in file names.
no_check_filenames: bool,
Expand Down Expand Up @@ -252,6 +257,13 @@ fn run() -> Result<i32, failure::Error> {
let options = Options::from_args().infer();

let mut config = config::Config::default();
if let Some(path) = options.custom_config.as_ref() {
let mut file = std::fs::File::open(path)?;
let mut s = String::new();
file.read_to_string(&mut s)?;
let custom: config::Config = toml::from_str(&s)?;
config.update(&custom);
}
config.update(&options);

let mut builder = get_logging(options.verbose.log_level());
Expand Down

0 comments on commit 3d4da68

Please sign in to comment.