Ensure selfupdate is enabled for SDKMAN! (#954)
* Ensure `selfupdate` is enabled for SDKMAN! This subcommand is unavailable when the `sdkman_selfupdate_feature` option is disabled, as is the case when SDKMAN! is installed via Homebrew. https://github.com/sdkman/sdkman-cli/pull/1042 * Fix macOS build; simplify Co-authored-by: Roey Darwish Dror <roey.ghost@gmail.com>
This commit is contained in:
@@ -41,6 +41,7 @@ notify-rust = "4.5.0"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
nix = "0.24.1"
|
||||
rust-ini = "0.18.0"
|
||||
self_update_crate = { version = "0.30.0", default-features = false, optional = true, package = "self_update", features = ["archive-tar", "compression-flate2", "rustls"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
@@ -48,9 +49,6 @@ self_update_crate = { version = "0.30.0", default-features = false, optional = t
|
||||
winapi = "0.3.9"
|
||||
parselnk = "0.1.0"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
rust-ini = "0.18.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::utils::{require, PathExt};
|
||||
use crate::Step;
|
||||
use anyhow::Result;
|
||||
use directories::BaseDirs;
|
||||
use ini::Ini;
|
||||
use log::debug;
|
||||
use std::fs;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
@@ -343,11 +344,26 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res
|
||||
|
||||
print_separator("SDKMAN!");
|
||||
|
||||
let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path);
|
||||
run_type
|
||||
.execute(&bash)
|
||||
.args(&["-c", cmd_selfupdate.as_str()])
|
||||
.check_run()?;
|
||||
let sdkman_config_path = env::var("SDKMAN_DIR")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|_| base_dirs.home_dir().join(".sdkman"))
|
||||
.join("etc")
|
||||
.join("config")
|
||||
.require()?;
|
||||
|
||||
let sdkman_config = Ini::load_from_file(sdkman_config_path)?;
|
||||
let selfupdate_enabled = sdkman_config
|
||||
.general_section()
|
||||
.get("sdkman_selfupdate_feature")
|
||||
.unwrap_or("false");
|
||||
|
||||
if selfupdate_enabled == "true" {
|
||||
let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path);
|
||||
run_type
|
||||
.execute(&bash)
|
||||
.args(&["-c", cmd_selfupdate.as_str()])
|
||||
.check_run()?;
|
||||
}
|
||||
|
||||
let cmd_update = format!("source {} && sdk update", &sdkman_init_path);
|
||||
run_type.execute(&bash).args(&["-c", cmd_update.as_str()]).check_run()?;
|
||||
|
||||
Reference in New Issue
Block a user