Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(paths): add os specific directory handling for windows #38

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ fn handle_main_command(
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
args: Args,
) -> Result<()> {
let config_file_path = dirs::home_dir()
.context("Unable to get home directory")?
.join(".config")
.join("donkeytype")
.join("donkeytype-config.json");
let config_file_path = if cfg!(target_os = "windows") {
dirs::config_local_dir().context("Unable to get local config directory")?
} else {
dirs::home_dir()
.context("Unable to get home directory")?
.join(".config")
}
.join("donkeytype")
.join("donkeytype-config.json");

let config = Config::new(args, config_file_path).context("Unable to create config")?;
let expected_input = ExpectedInput::new(&config).context("Unable to create expected input")?;

Expand Down Expand Up @@ -234,11 +239,15 @@ mod tests {
}

fn setup_terminal(args: Args) -> Result<(Config, ExpectedInput, Terminal<TestBackend>)> {
let config_file_path = dirs::home_dir()
.context("Unable to get home directory")?
.join(".config")
.join("donkeytype")
.join("donkeytype-config.json");
let config_file_path = if cfg!(target_os = "windows") {
dirs::config_local_dir().context("Unable to get local config directory")?
} else {
dirs::home_dir()
.context("Unable to get home directory")?
.join(".config")
}
.join("donkeytype")
.join("donkeytype-config.json");

let config = Config::new(args, config_file_path).context("Unable to create config")?;
let expected_input =
Expand Down
14 changes: 9 additions & 5 deletions src/test_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,15 @@ fn render_chart(
}

fn get_results_dir_path() -> Result<PathBuf> {
let dir_path = dirs::home_dir()
.context("Unable to get home directory")?
.join(".local")
.join("share")
.join("donkeytype");
let dir_path = if cfg!(target_os = "windows") {
dirs::config_local_dir().context("Unable to get local config directory")?
} else {
dirs::home_dir()
.context("Unable to get home directory")?
.join(".local")
.join("share")
}
.join("donkeytype");

Ok(dir_path)
}
Expand Down