mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
feat: Accept config on command-line
This commit is contained in:
parent
8d96a2ad1d
commit
3d4da686ad
3 changed files with 23 additions and 0 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
12
src/main.rs
12
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<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,
|
||||
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue