Skip to content

Commit

Permalink
Ensure selfupdate is enabled for SDKMAN! (#954)
Browse files Browse the repository at this point in the history
* 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.

sdkman/sdkman-cli#1042

* Fix macOS build; simplify

Co-authored-by: Roey Darwish Dror <[email protected]>
  • Loading branch information
ahutsunshin and r-darwish authored Sep 29, 2023
1 parent 0a8a654 commit 0f9f471
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ 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]
self_update_crate = { version = "0.30.0", default-features = false, optional = true, package = "self_update", features = ["archive-zip", "compression-zip-deflate", "rustls"] }
winapi = "0.3.9"
parselnk = "0.1.0"

[target.'cfg(target_os = "linux")'.dependencies]
rust-ini = "0.18.0"

[profile.release]
lto = true

Expand Down
26 changes: 21 additions & 5 deletions src/steps/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()?;
Expand Down

0 comments on commit 0f9f471

Please sign in to comment.