Skip to content

Commit c08b63c

Browse files
Implementing System ENV Output Path
Closes #17
1 parent 0034151 commit c08b63c

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rad/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rad"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2021"
55
readme = "../README.md"
66
license = "Apache-2.0"

rad/src/commands/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use std::env::VarError;
12
use std::path::PathBuf;
23

34
use clap::{Parser, Subcommand};
45
use command::Command;
56
use directories::BaseDirs;
6-
use tracing::debug;
7+
use tracing::{debug, error};
78

89
use self::{check::CheckCommand, download::DownloadCommand, get_versions::GetVersionsCommand};
910
use rust_analyzer_downloader::services::downloader::Downloader;
@@ -44,7 +45,7 @@ pub struct Cli {
4445
commands: Commands,
4546
}
4647

47-
fn get_default_output_path() -> String {
48+
fn default_user_output_path() -> String {
4849
let base_dirs = BaseDirs::new().unwrap();
4950
let home_dir = base_dirs.home_dir();
5051

@@ -60,6 +61,28 @@ fn get_default_output_path() -> String {
6061
buf.as_path().to_string_lossy().into()
6162
}
6263

64+
fn get_default_output_path() -> String {
65+
let env = std::env::var("RAD_OUTPUT_PATH");
66+
67+
match env {
68+
Ok(path) => path,
69+
Err(VarError::NotUnicode(os_str)) => {
70+
error!("RAD_OUTPUT_PATH is not unicode: {:?}", os_str);
71+
72+
default_user_output_path()
73+
}
74+
Err(VarError::NotPresent) => {
75+
let path = default_user_output_path();
76+
debug!(
77+
path = path.as_str(),
78+
"RAD_OUTPUT_PATH not present, using default path"
79+
);
80+
81+
path
82+
}
83+
}
84+
}
85+
6386
// #[tracing::instrument]
6487
pub async fn execute() -> Result<(), Box<dyn std::error::Error>> {
6588
let args = Cli::parse();

0 commit comments

Comments
 (0)