@@ -822,46 +822,50 @@ fn detect_subcommand(file_path: &Path, cursor: Option<Position>) -> String {
822
822
/// Handle self-update command
823
823
async fn handle_self_update ( force : bool ) -> anyhow:: Result < ( ) > {
824
824
use std:: process:: Stdio ;
825
-
825
+
826
826
println ! ( "{} Checking for updates..." , OutputFormatter :: info( "RAZ" ) ) ;
827
-
827
+
828
828
// Get current version
829
829
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
+
832
836
// Check if running from cargo install or system PATH
833
837
let current_exe = env:: current_exe ( ) ?;
834
838
let exe_dir = current_exe. parent ( ) . unwrap ( ) ;
835
-
839
+
836
840
// 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
+
840
844
if !is_cargo_installed {
841
845
// 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
+
846
848
if let Ok ( output) = which_result {
847
849
let path = String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) ;
848
850
if !path. is_empty ( ) && !path. contains ( ".cargo" ) {
849
851
println ! (
850
852
"\n {} RAZ appears to be installed via a package manager or custom installation." ,
851
853
OutputFormatter :: warning( "Note" )
852
854
) ;
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." ) ;
856
856
return Ok ( ( ) ) ;
857
857
}
858
858
}
859
859
}
860
-
860
+
861
861
// Get latest version from GitHub API
862
862
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
+
865
869
// Compare versions
866
870
if !force && current_version == latest_version. trim_start_matches ( 'v' ) {
867
871
println ! (
@@ -870,36 +874,39 @@ async fn handle_self_update(force: bool) -> anyhow::Result<()> {
870
874
) ;
871
875
return Ok ( ( ) ) ;
872
876
}
873
-
877
+
874
878
// Prompt for confirmation
875
879
if !force {
876
- print ! ( "\n Update RAZ from v{} to {}? [Y/n] " , current_version , latest_version ) ;
880
+ print ! ( "\n Update RAZ from v{current_version } to {latest_version }? [Y/n] " ) ;
877
881
use std:: io:: { self , Write } ;
878
882
io:: stdout ( ) . flush ( ) ?;
879
-
883
+
880
884
let mut input = String :: new ( ) ;
881
885
io:: stdin ( ) . read_line ( & mut input) ?;
882
886
let choice = input. trim ( ) . to_lowercase ( ) ;
883
-
884
- if choice != "y" && choice != "" {
887
+
888
+ if choice != "y" && !choice . is_empty ( ) {
885
889
println ! ( "Update cancelled." ) ;
886
890
return Ok ( ( ) ) ;
887
891
}
888
892
}
889
-
893
+
890
894
// Perform update using cargo install
891
895
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
+
894
901
let mut cmd = process:: Command :: new ( "cargo" ) ;
895
902
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
+
901
908
let status = cmd. status ( ) ?;
902
-
909
+
903
910
if status. success ( ) {
904
911
println ! (
905
912
"\n {} RAZ has been successfully updated to {}!" ,
@@ -914,49 +921,49 @@ async fn handle_self_update(force: bool) -> anyhow::Result<()> {
914
921
} else {
915
922
anyhow:: bail!( "Failed to update RAZ. Please try again or install manually." ) ;
916
923
}
917
-
924
+
918
925
Ok ( ( ) )
919
926
}
920
927
921
928
/// Get latest version from GitHub releases
922
929
async fn get_latest_version ( ) -> anyhow:: Result < String > {
923
930
// Get all releases, not just the "latest" (which might be wrong)
924
931
let url = "https://api.github.com/repos/codeitlikemiley/raz/releases?per_page=20" ;
925
-
932
+
926
933
// Use a simple HTTPS request
927
934
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] )
929
936
. output ( ) ?;
930
-
937
+
931
938
if !output. status . success ( ) {
932
939
anyhow:: bail!( "Failed to fetch versions from GitHub" ) ;
933
940
}
934
-
941
+
935
942
let response = String :: from_utf8 ( output. stdout ) ?;
936
-
943
+
937
944
// Parse JSON to get all releases
938
945
let releases: Vec < serde_json:: Value > = serde_json:: from_str ( & response) ?;
939
-
946
+
940
947
if releases. is_empty ( ) {
941
948
anyhow:: bail!( "No releases found" ) ;
942
949
}
943
-
950
+
944
951
// Find the highest version that looks like a CLI release (not vscode-specific)
945
952
let mut highest_version = String :: new ( ) ;
946
953
let mut highest_semver = ( 0 , 0 , 0 ) ;
947
-
954
+
948
955
for release in releases {
949
956
if let Some ( tag_name) = release[ "tag_name" ] . as_str ( ) {
950
957
// Skip pre-releases unless there are no stable releases
951
958
if release[ "prerelease" ] . as_bool ( ) . unwrap_or ( false ) {
952
959
continue ;
953
960
}
954
-
961
+
955
962
// Skip VS Code specific releases
956
963
if tag_name. contains ( "vscode" ) {
957
964
continue ;
958
965
}
959
-
966
+
960
967
// Parse semantic version (handle v prefix)
961
968
let version_str = tag_name. trim_start_matches ( 'v' ) ;
962
969
if let Some ( ( major, minor, patch) ) = parse_semver ( version_str) {
@@ -967,11 +974,11 @@ async fn get_latest_version() -> anyhow::Result<String> {
967
974
}
968
975
}
969
976
}
970
-
977
+
971
978
if highest_version. is_empty ( ) {
972
979
anyhow:: bail!( "No valid CLI releases found" ) ;
973
980
}
974
-
981
+
975
982
Ok ( highest_version)
976
983
}
977
984
0 commit comments