From 3d4da686ad8d3d02b3a5224cecbe0c4a9184da99 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Aug 2019 09:55:17 -0500 Subject: [PATCH] feat: Accept config on command-line --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3286311..daefb43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -799,6 +799,14 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "toml" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "treeline" version = "0.1.0" @@ -826,6 +834,7 @@ dependencies = [ "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1028,6 +1037,7 @@ dependencies = [ "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" diff --git a/Cargo.toml b/Cargo.toml index bc9cb67..4bb7a8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index e15ff70..48b7d87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ #[macro_use] extern crate clap; +use std::io::Read; use std::io::Write; use structopt::StructOpt; @@ -42,6 +43,10 @@ struct Options { /// Paths to check path: Vec, + #[structopt(short = "c", long = "config")] + /// Custom config file + custom_config: Option, + #[structopt(long, raw(overrides_with = r#""check-filenames""#))] /// Skip verifying spelling in file names. no_check_filenames: bool, @@ -252,6 +257,13 @@ fn run() -> Result { 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());