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