Skip to content

Commit 145331d

Browse files
added clean install and self-update
1 parent 514a1ee commit 145331d

File tree

3 files changed

+107
-159
lines changed

3 files changed

+107
-159
lines changed

raz-adapters/cli/src/main.rs

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -822,46 +822,50 @@ fn detect_subcommand(file_path: &Path, cursor: Option<Position>) -> String {
822822
/// Handle self-update command
823823
async fn handle_self_update(force: bool) -> anyhow::Result<()> {
824824
use std::process::Stdio;
825-
825+
826826
println!("{} Checking for updates...", OutputFormatter::info("RAZ"));
827-
827+
828828
// Get current version
829829
let current_version = env!("CARGO_PKG_VERSION");
830-
println!("{} Current version: v{}", OutputFormatter::label("Info"), current_version);
831-
830+
println!(
831+
"{} Current version: v{}",
832+
OutputFormatter::label("Info"),
833+
current_version
834+
);
835+
832836
// Check if running from cargo install or system PATH
833837
let current_exe = env::current_exe()?;
834838
let exe_dir = current_exe.parent().unwrap();
835-
839+
836840
// Check if we're in a cargo bin directory
837-
let is_cargo_installed = exe_dir.to_string_lossy().contains(".cargo/bin") ||
838-
exe_dir.to_string_lossy().contains(".cargo\\bin");
839-
841+
let is_cargo_installed = exe_dir.to_string_lossy().contains(".cargo/bin")
842+
|| exe_dir.to_string_lossy().contains(".cargo\\bin");
843+
840844
if !is_cargo_installed {
841845
// Check if it's in system PATH but not cargo
842-
let which_result = process::Command::new("which")
843-
.arg("raz")
844-
.output();
845-
846+
let which_result = process::Command::new("which").arg("raz").output();
847+
846848
if let Ok(output) = which_result {
847849
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
848850
if !path.is_empty() && !path.contains(".cargo") {
849851
println!(
850852
"\n{} RAZ appears to be installed via a package manager or custom installation.",
851853
OutputFormatter::warning("Note")
852854
);
853-
println!(
854-
"Please update using the same method you used to install RAZ."
855-
);
855+
println!("Please update using the same method you used to install RAZ.");
856856
return Ok(());
857857
}
858858
}
859859
}
860-
860+
861861
// Get latest version from GitHub API
862862
let latest_version = get_latest_version().await?;
863-
println!("{} Latest version: {}", OutputFormatter::label("Info"), latest_version);
864-
863+
println!(
864+
"{} Latest version: {}",
865+
OutputFormatter::label("Info"),
866+
latest_version
867+
);
868+
865869
// Compare versions
866870
if !force && current_version == latest_version.trim_start_matches('v') {
867871
println!(
@@ -870,36 +874,39 @@ async fn handle_self_update(force: bool) -> anyhow::Result<()> {
870874
);
871875
return Ok(());
872876
}
873-
877+
874878
// Prompt for confirmation
875879
if !force {
876-
print!("\nUpdate RAZ from v{} to {}? [Y/n] ", current_version, latest_version);
880+
print!("\nUpdate RAZ from v{current_version} to {latest_version}? [Y/n] ");
877881
use std::io::{self, Write};
878882
io::stdout().flush()?;
879-
883+
880884
let mut input = String::new();
881885
io::stdin().read_line(&mut input)?;
882886
let choice = input.trim().to_lowercase();
883-
884-
if choice != "y" && choice != "" {
887+
888+
if choice != "y" && !choice.is_empty() {
885889
println!("Update cancelled.");
886890
return Ok(());
887891
}
888892
}
889-
893+
890894
// Perform update using cargo install
891895
println!("\n{} Updating RAZ...", OutputFormatter::info("Installing"));
892-
println!("{} This may take a few minutes...", OutputFormatter::dim("Note"));
893-
896+
println!(
897+
"{} This may take a few minutes...",
898+
OutputFormatter::dim("Note")
899+
);
900+
894901
let mut cmd = process::Command::new("cargo");
895902
cmd.arg("install")
896-
.arg("raz-cli")
897-
.arg("--force")
898-
.stdout(Stdio::inherit())
899-
.stderr(Stdio::inherit());
900-
903+
.arg("raz-cli")
904+
.arg("--force")
905+
.stdout(Stdio::inherit())
906+
.stderr(Stdio::inherit());
907+
901908
let status = cmd.status()?;
902-
909+
903910
if status.success() {
904911
println!(
905912
"\n{} RAZ has been successfully updated to {}!",
@@ -914,49 +921,49 @@ async fn handle_self_update(force: bool) -> anyhow::Result<()> {
914921
} else {
915922
anyhow::bail!("Failed to update RAZ. Please try again or install manually.");
916923
}
917-
924+
918925
Ok(())
919926
}
920927

921928
/// Get latest version from GitHub releases
922929
async fn get_latest_version() -> anyhow::Result<String> {
923930
// Get all releases, not just the "latest" (which might be wrong)
924931
let url = "https://api.github.com/repos/codeitlikemiley/raz/releases?per_page=20";
925-
932+
926933
// Use a simple HTTPS request
927934
let output = process::Command::new("curl")
928-
.args(&["-s", "-H", "Accept: application/vnd.github.v3+json", url])
935+
.args(["-s", "-H", "Accept: application/vnd.github.v3+json", url])
929936
.output()?;
930-
937+
931938
if !output.status.success() {
932939
anyhow::bail!("Failed to fetch versions from GitHub");
933940
}
934-
941+
935942
let response = String::from_utf8(output.stdout)?;
936-
943+
937944
// Parse JSON to get all releases
938945
let releases: Vec<serde_json::Value> = serde_json::from_str(&response)?;
939-
946+
940947
if releases.is_empty() {
941948
anyhow::bail!("No releases found");
942949
}
943-
950+
944951
// Find the highest version that looks like a CLI release (not vscode-specific)
945952
let mut highest_version = String::new();
946953
let mut highest_semver = (0, 0, 0);
947-
954+
948955
for release in releases {
949956
if let Some(tag_name) = release["tag_name"].as_str() {
950957
// Skip pre-releases unless there are no stable releases
951958
if release["prerelease"].as_bool().unwrap_or(false) {
952959
continue;
953960
}
954-
961+
955962
// Skip VS Code specific releases
956963
if tag_name.contains("vscode") {
957964
continue;
958965
}
959-
966+
960967
// Parse semantic version (handle v prefix)
961968
let version_str = tag_name.trim_start_matches('v');
962969
if let Some((major, minor, patch)) = parse_semver(version_str) {
@@ -967,11 +974,11 @@ async fn get_latest_version() -> anyhow::Result<String> {
967974
}
968975
}
969976
}
970-
977+
971978
if highest_version.is_empty() {
972979
anyhow::bail!("No valid CLI releases found");
973980
}
974-
981+
975982
Ok(highest_version)
976983
}
977984

raz-adapters/vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
"command": "raz.showDebugInfo",
100100
"title": "Show Debug Info",
101101
"category": "RAZ"
102+
},
103+
{
104+
"command": "raz.resetBinary",
105+
"title": "Reset RAZ Binary (Clean Install)",
106+
"category": "RAZ"
102107
}
103108
],
104109
"keybindings": [

0 commit comments

Comments
 (0)