Skip to content

Commit

Permalink
Use XDG conventions on macOS too (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 authored Apr 26, 2023
1 parent 8f286cc commit c4bd7ce
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 46 deletions.
131 changes: 93 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ num-format = "0.4.0"
once_cell = "1.9"
regex = "1.5"
serde_json = "1"
dirs = "4"
etcetera = "0.8"

[dependencies.env_logger]
features = []
Expand Down
19 changes: 12 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{env, fs, path::PathBuf};

use etcetera::BaseStrategy;

use crate::language::LanguageType;
use crate::sort::Sort;
use crate::stats::Report;
Expand Down Expand Up @@ -74,11 +76,11 @@ impl Config {
/// The current directory's configuration will take priority over the configuration
/// directory.
///
/// |Platform | Value | Example |
/// | ------- | ----- | ------- |
/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config |
/// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support |
/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming |
/// |Platform | Value | Example |
/// | ------- | ------------------------------------- | ------------------------------ |
/// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config |
/// | macOS | `$XDG_CONFIG_HOME` or `$HOME`/.config | /Users/alice/.config |
/// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming |
///
/// # Example
/// ```toml
Expand All @@ -90,11 +92,14 @@ impl Config {
// /// extensions = ["py3"]
/// ```
pub fn from_config_files() -> Self {
let conf_dir = dirs::config_dir()
let conf_dir = etcetera::choose_base_strategy()
.ok()
.map(|basedirs| basedirs.config_dir())
.and_then(Self::get_config)
.unwrap_or_default();

let home_dir = dirs::home_dir()
let home_dir = etcetera::home_dir()
.ok()
.and_then(Self::get_config)
.unwrap_or_default();

Expand Down

0 comments on commit c4bd7ce

Please sign in to comment.