expand tilde in config file (#102)

This commit is contained in:
Clément DOUIN 2021-08-05 23:18:28 +02:00
parent a6b30b746c
commit 97054d3133
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
4 changed files with 59 additions and 4 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Config option `signature-delimiter` to customize the signature delimiter (default to `-- \n`) [[#114](https://github.com/soywod/himalaya/pull/114)] - Config option `signature-delimiter` to customize the signature delimiter (default to `-- \n`) [[#114](https://github.com/soywod/himalaya/pull/114)]
- Expand tilde and env vars for `downloads-dir` and `signature` [#102]
### Fixed ### Fixed
@ -285,6 +286,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#95]: https://github.com/soywod/himalaya/issues/95 [#95]: https://github.com/soywod/himalaya/issues/95
[#96]: https://github.com/soywod/himalaya/issues/96 [#96]: https://github.com/soywod/himalaya/issues/96
[#100]: https://github.com/soywod/himalaya/issues/100 [#100]: https://github.com/soywod/himalaya/issues/100
[#102]: https://github.com/soywod/himalaya/issues/102
[#109]: https://github.com/soywod/himalaya/issues/109 [#109]: https://github.com/soywod/himalaya/issues/109
[#117]: https://github.com/soywod/himalaya/issues/117 [#117]: https://github.com/soywod/himalaya/issues/117
[#121]: https://github.com/soywod/himalaya/issues/121 [#121]: https://github.com/soywod/himalaya/issues/121

41
Cargo.lock generated
View file

@ -195,6 +195,27 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if 1.0.0",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.26" version = "0.8.26"
@ -328,6 +349,7 @@ dependencies = [
"rfc2047-decoder", "rfc2047-decoder",
"serde", "serde",
"serde_json", "serde_json",
"shellexpand",
"terminal_size", "terminal_size",
"toml", "toml",
"tree_magic", "tree_magic",
@ -809,6 +831,16 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "redox_users"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom",
"redox_syscall 0.2.8",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.5.4" version = "1.5.4"
@ -937,6 +969,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "shellexpand"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83bdb7831b2d85ddf4a7b148aa19d0587eddbe8671a436b7bd1182eaad0f2829"
dependencies = [
"dirs-next",
]
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.6.1" version = "1.6.1"

View file

@ -19,6 +19,7 @@ native-tls = "0.2"
rfc2047-decoder = "0.1.2" rfc2047-decoder = "0.1.2"
serde = {version = "1.0.118", features = ["derive"]} serde = {version = "1.0.118", features = ["derive"]}
serde_json = "1.0.61" serde_json = "1.0.61"
shellexpand = "2.1.0"
terminal_size = "0.1.15" terminal_size = "0.1.15"
toml = "0.5.8" toml = "0.5.8"
tree_magic = "0.2.3" tree_magic = "0.2.3"

View file

@ -2,6 +2,7 @@ use error_chain::error_chain;
use lettre::transport::smtp::authentication::Credentials as SmtpCredentials; use lettre::transport::smtp::authentication::Credentials as SmtpCredentials;
use log::debug; use log::debug;
use serde::Deserialize; use serde::Deserialize;
use shellexpand;
use std::{ use std::{
collections::HashMap, collections::HashMap,
env, env,
@ -230,8 +231,17 @@ impl Config {
account account
.downloads_dir .downloads_dir
.as_ref() .as_ref()
.unwrap_or(self.downloads_dir.as_ref().unwrap_or(&env::temp_dir())) .and_then(|dir| dir.to_str())
.to_owned() .and_then(|dir| shellexpand::full(dir).ok())
.map(|dir| PathBuf::from(dir.to_string()))
.unwrap_or(
self.downloads_dir
.as_ref()
.and_then(|dir| dir.to_str())
.and_then(|dir| shellexpand::full(dir).ok())
.map(|dir| PathBuf::from(dir.to_string()))
.unwrap_or(env::temp_dir()),
)
.join(filename) .join(filename)
} }
@ -264,8 +274,9 @@ impl Config {
.signature .signature
.as_ref() .as_ref()
.or_else(|| self.signature.as_ref()); .or_else(|| self.signature.as_ref());
sig.and_then(|sig| shellexpand::full(sig).ok())
sig.and_then(|sig| fs::read_to_string(sig).ok()) .map(|sig| sig.to_string())
.and_then(|sig| fs::read_to_string(sig).ok())
.or_else(|| sig.map(|sig| sig.to_owned())) .or_else(|| sig.map(|sig| sig.to_owned()))
.map(|sig| String::new() + sig_delim + sig.as_ref()) .map(|sig| String::new() + sig_delim + sig.as_ref())
} }