Commit 963ce3c7c2
Unregistered key
Layout: unified · split
src/config.rs +16 −7
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | use std::borrow::Cow; |
| 3 | 3 | use std::collections::hash_map::DefaultHasher; |
| 4 | 4 | use std::collections::{BTreeMap, HashMap}; |
| 5 | use std::env; | |
| 5 | 6 | use std::fmt; |
| 6 | 7 | use std::fs::File; |
| 7 | 8 | use std::hash::{Hash, Hasher}; |
| @@ -837,14 +838,22 @@ pub struct ApplicationSettings { | ||
| 837 | 838 | } |
| 838 | 839 | |
| 839 | 840 | impl ApplicationSettings { |
| 841 | fn get_xdg_config_home() -> Option<PathBuf> { | |
| 842 | env::var("XDG_CONFIG_HOME").ok().map(PathBuf::from) | |
| 843 | } | |
| 844 | ||
| 840 | 845 | pub fn load(cli: Iamb) -> Result<Self, Box<dyn std::error::Error>> { |
| 841 | let mut config_dir = cli.config_directory.or_else(dirs::config_dir).unwrap_or_else(|| { | |
| 842 | usage!( | |
| 843 | "No user configuration directory found;\ | |
| 844 | please specify one via -C.\n\n | |
| 845 | For more information try '--help'" | |
| 846 | ); | |
| 847 | }); | |
| 846 | let mut config_dir = cli | |
| 847 | .config_directory | |
| 848 | .or_else(Self::get_xdg_config_home) | |
| 849 | .or_else(dirs::config_dir) | |
| 850 | .unwrap_or_else(|| { | |
| 851 | usage!( | |
| 852 | "No user configuration directory found;\ | |
| 853 | please specify one via -C.\n\n | |
| 854 | For more information try '--help'" | |
| 855 | ); | |
| 856 | }); | |
| 848 | 857 | |
| 849 | 858 | config_dir.push("iamb"); |
| 850 | 859 | let config_json = config_dir.join("config.json"); |