Skip to content

Commit

Permalink
Merge pull request #15 from spencerwooo:create-config-dir
Browse files Browse the repository at this point in the history
Create config parent if not exists
  • Loading branch information
spencerwooo authored Jan 7, 2023
2 parents 26caf18 + 5b10929 commit c680794
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ pub enum ConfigError {
/// * If config file does not exist, creates default config file to path and returns error.
/// * If found, tries to parse the file and returns error if parse fails or fields found undefined.
pub fn parse_config(path: &str, prefix: &str) -> Result<Config, ConfigError> {
// Create `~/.config` directory if not exists
let parent_dir = Path::new(path).parent().unwrap();
if !parent_dir.exists() {
fs::create_dir_all(parent_dir).unwrap();
}

// Create clashrup default config if not exists
let config_path = Path::new(path);
if !config_path.exists() {
Expand Down

0 comments on commit c680794

Please sign in to comment.