on master help sign in
Add possibility for spaces on a single line
commit693bd5929d856dd046ca5bd7316c5db4c9a1ee9c authorsharkdp <davidpeter@web.de> dateThu 11 Oct 2018, 21:39 (8 years ago) parent8275b04
3 files changed+13−3
Cargo.lock+7 Cargo.toml+1 src/config.rs+5−3
Cargo.lock+7
@@ -68,6 +68,7 @@ dependencies = [
6868 "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
6969 "git2 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
7070 "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
71+ "shell-words 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
7172 "syntect 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
7273 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
7374 "wild 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -677,6 +678,11 @@ dependencies = [
677678 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
678679]
679680
681+[[package]]
682+name = "shell-words"
683+version = "0.1.0"
684+source = "registry+https://github.com/rust-lang/crates.io-index"
685+
680686[[package]]
681687name = "smallvec"
682688version = "0.6.5"
@@ -1010,6 +1016,7 @@ dependencies = [
10101016"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9"
10111017"checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe"
10121018"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce"
1019+"checksum shell-words 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39acde55a154c4cd3ae048ac78cc21c25f3a0145e44111b523279113dce0d94a"
10131020"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"
10141021"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
10151022"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
Cargo.toml+1
@@ -24,6 +24,7 @@ lazy_static = "1.0"
2424wild = "2.0"
2525content_inspector = "0.2.3"
2626encoding = "0.2"
27+shell-words = "0.1.0"
2728
2829[dependencies.git2]
2930version = "0.7"
src/config.rs+5−3
@@ -1,6 +1,8 @@
11use std::ffi::OsString;
22use std::fs;
33
4+use shell_words;
5+
46use dirs::PROJECT_DIRS;
57
68pub fn get_args_from_config_file() -> Vec<OsString> {
@@ -16,6 +18,7 @@ fn get_args_from_str<'a>(content: &'a str) -> Vec<OsString> {
1618 .map(|line| line.trim())
1719 .filter(|line| !line.is_empty())
1820 .filter(|line| !line.starts_with("#"))
21+ .flat_map(|line| shell_words::split(line).unwrap())
1922 .map(|line| line.into())
2023 .collect()
2124}
@@ -23,7 +26,6 @@ fn get_args_from_str<'a>(content: &'a str) -> Vec<OsString> {
2326#[test]
2427fn empty() {
2528 let args = get_args_from_str("");
26− println!("{:?}", args);
2729 assert!(args.is_empty());
2830}
2931
@@ -41,7 +43,7 @@ fn multiple() {
4143 --color=always
4244 ";
4345 assert_eq!(
44− vec!["-p", "--style numbers,changes", "--color=always"],
46+ vec!["-p", "--style", "numbers,changes", "--color=always"],
4547 get_args_from_str(config)
4648 );
4749}
@@ -59,7 +61,7 @@ fn comments() {
5961 --color=always
6062 ";
6163 assert_eq!(
62− vec!["-p", "--style numbers,changes", "--color=always"],
64+ vec!["-p", "--style", "numbers,changes", "--color=always"],
6365 get_args_from_str(config)
6466 );
6567}