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

feat(sdk): allow global ~/.clarinet/Settings.toml #1208

Merged
merged 7 commits into from
Oct 25, 2023
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions components/clarinet-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ lazy_static = "1.4.0"
atty = "0.2.14"
termcolor = "1.1.2"
regex = "1.7"
dirs = { version = "4.0.0" }
libc = "0.2.86"
encoding_rs = "0.8.31"
percent-encoding = "2.1.0"
64 changes: 55 additions & 9 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
@@ -550,6 +550,11 @@ struct Check {
pub use_computed_deployment_plan: bool,
}

#[derive(Serialize, Deserialize)]
struct GlobalSettings {
disable_hints: bool,
enable_telemetry: Option<bool>,
}
#[derive(Parser, PartialEq, Clone, Debug)]
struct Completions {
/// Specify which shell to generation completions script for
@@ -579,7 +584,40 @@ pub fn main() {
}
};

let mut global_settings = String::new();
let global_settings_default = GlobalSettings {
disable_hints: false,
enable_telemetry: None,
};
// This is backwards compatible with ENV var setting as well as the new ~/.clarinet/Settings.toml
let hints_enabled = env::var("CLARINET_DISABLE_HINTS") != Ok("1".into());
let home_dir = dirs::home_dir();
let mpath: Option<PathBuf> = home_dir.map(|home_dir| home_dir.join(".clarinet/Settings.toml"));
let settings_file = "~/.clarinet/Settings.toml";
let global_settings: GlobalSettings = match mpath {
Some(path) => {
if path.exists() {
let mut file = File::open(&path).expect("Unable to open the file");
let result = file.read_to_string(&mut global_settings);
match result {
Ok(_) => match toml::from_str(&global_settings) {
Ok(res) => res,
Err(_) => {
println!("{}{}", format_warn!("unable to parse "), settings_file);
global_settings_default
}
},
Err(_) => {
println!("{}{}", format_warn!("unable to read file "), settings_file);
global_settings_default
}
}
} else {
global_settings_default
}
}
None => global_settings_default,
};

match opts.command {
Command::New(project_opts) => {
@@ -598,15 +636,23 @@ pub fn main() {
if project_opts.disable_telemetry {
false
} else {
println!("{}", yellow!("Send usage data to Hiro."));
println!("{}", yellow!("Help Hiro improve its products and services by automatically sending diagnostics and usage data."));
println!("{}", yellow!("Only high level usage information, and no information identifying you or your project are collected."));
// TODO(lgalabru): once we have a privacy policy available, add a link
// println!("{}", yellow!("Visit http://hiro.so/clarinet-privacy for details."));
println!("{}", yellow!("Enable [Y/n]?"));
let mut buffer = String::new();
std::io::stdin().read_line(&mut buffer).unwrap();
!buffer.starts_with("n")
let enabled = match global_settings.enable_telemetry {
Some(true) => true,
_ => env::var("CLARINET_TELEMETRY") == Ok("1".into()),
};
if enabled {
true
} else {
println!("{}", yellow!("Send usage data to Hiro."));
println!("{}", yellow!("Help Hiro improve its products and services by automatically sending diagnostics and usage data."));
println!("{}", yellow!("Only high level usage information, and no information identifying you or your project are collected."));
// TODO(lgalabru): once we have a privacy policy available, add a link
// println!("{}", yellow!("Visit http://hiro.so/clarinet-privacy for details."));
println!("{}", yellow!("Enable [Y/n]?"));
let mut buffer = String::new();
std::io::stdin().read_line(&mut buffer).unwrap();
!buffer.starts_with("n")
}
}
} else {
false