@@ -14,28 +14,93 @@ use cli_table::{
14
14
use itertools:: Itertools ;
15
15
use numeric_sort:: cmp;
16
16
17
- fn get_alias_update_info (
18
- target : & str ,
17
+ fn format_linked_command ( command : & str , args : & Option < Vec < String > > ) -> String {
18
+ let mut combined_command = String :: new ( ) ;
19
+
20
+ if command. contains ( ' ' ) {
21
+ combined_command. push ( '\"' ) ;
22
+ combined_command. push_str ( command) ;
23
+ combined_command. push ( '\"' ) ;
24
+ } else {
25
+ combined_command. push_str ( command) ;
26
+ }
27
+
28
+ if let Some ( args) = args {
29
+ for arg in args {
30
+ combined_command. push ( ' ' ) ;
31
+ if arg. contains ( ' ' ) {
32
+ combined_command. push ( '\"' ) ;
33
+ combined_command. push_str ( arg) ;
34
+ combined_command. push ( '\"' ) ;
35
+ } else {
36
+ combined_command. push_str ( arg) ;
37
+ }
38
+ }
39
+ }
40
+
41
+ format ! ( "Linked to `{combined_command}`" )
42
+ }
43
+
44
+ fn format_version ( channel : & JuliaupConfigChannel ) -> String {
45
+ match channel {
46
+ JuliaupConfigChannel :: DirectDownloadChannel { version, .. } => {
47
+ format ! ( "Development version {version}" )
48
+ }
49
+ JuliaupConfigChannel :: SystemChannel { version } => version. clone ( ) ,
50
+ JuliaupConfigChannel :: LinkedChannel { command, args } => {
51
+ format_linked_command ( command, args)
52
+ }
53
+ JuliaupConfigChannel :: AliasChannel { target, args } => match args {
54
+ Some ( args) if !args. is_empty ( ) => {
55
+ format ! ( "Alias to `{target}` with args: {:?}" , args)
56
+ }
57
+ _ => format ! ( "Alias to `{target}`" ) ,
58
+ } ,
59
+ }
60
+ }
61
+
62
+ fn get_update_info (
63
+ channel_name : & str ,
64
+ channel : & JuliaupConfigChannel ,
19
65
config_file : & JuliaupReadonlyConfigFile ,
20
66
versiondb_data : & JuliaupVersionDB ,
21
- ) -> Option < String > {
22
- // Check if the target channel has updates available
23
- match config_file. data . installed_channels . get ( target) {
24
- Some ( JuliaupConfigChannel :: SystemChannel { version } ) => {
25
- match versiondb_data. available_channels . get ( target) {
26
- Some ( channel) if channel. version != * version => {
67
+ ) -> String {
68
+ match channel {
69
+ JuliaupConfigChannel :: DirectDownloadChannel {
70
+ local_etag,
71
+ server_etag,
72
+ ..
73
+ } => ( local_etag != server_etag) . then ( || "Update available" . to_string ( ) ) ,
74
+ JuliaupConfigChannel :: SystemChannel { version } => {
75
+ match versiondb_data. available_channels . get ( channel_name) {
76
+ Some ( channel) if & channel. version != version => {
27
77
Some ( format ! ( "Update to {} available" , channel. version) )
28
78
}
29
79
_ => None ,
30
80
}
31
81
}
32
- Some ( JuliaupConfigChannel :: DirectDownloadChannel {
33
- local_etag,
34
- server_etag,
35
- ..
36
- } ) => ( local_etag != server_etag) . then ( || "Update available" . to_string ( ) ) ,
37
- _ => None , // Target channel doesn't exist or not updatable
82
+ JuliaupConfigChannel :: LinkedChannel { .. } => None ,
83
+ JuliaupConfigChannel :: AliasChannel { target, .. } => {
84
+ // Check if the target channel has updates available
85
+ match config_file. data . installed_channels . get ( target) {
86
+ Some ( JuliaupConfigChannel :: DirectDownloadChannel {
87
+ local_etag,
88
+ server_etag,
89
+ ..
90
+ } ) => ( local_etag != server_etag) . then ( || "Update available" . to_string ( ) ) ,
91
+ Some ( JuliaupConfigChannel :: SystemChannel { version } ) => {
92
+ match versiondb_data. available_channels . get ( target) {
93
+ Some ( channel) if channel. version != * version => {
94
+ Some ( format ! ( "Update to {} available" , channel. version) )
95
+ }
96
+ _ => None ,
97
+ }
98
+ }
99
+ _ => None , // Target channel doesn't exist or not updatable
100
+ }
101
+ }
38
102
}
103
+ . unwrap_or_default ( )
39
104
}
40
105
41
106
#[ derive( Table ) ]
@@ -57,90 +122,19 @@ pub fn run_command_status(paths: &GlobalPaths) -> Result<()> {
57
122
let versiondb_data =
58
123
load_versions_db ( paths) . with_context ( || "`status` command failed to load versions db." ) ?;
59
124
60
- let rows_in_table: Vec < _ > = config_file
125
+ let rows_in_table: Vec < ChannelRow > = config_file
61
126
. data
62
127
. installed_channels
63
128
. iter ( )
64
- . sorted_by ( |a, b| cmp ( & a. 0 . to_string ( ) , & b. 0 . to_string ( ) ) )
65
- . map ( |i| -> ChannelRow {
66
- ChannelRow {
67
- default : match config_file. data . default {
68
- Some ( ref default_value) => {
69
- if i. 0 == default_value {
70
- "*"
71
- } else {
72
- ""
73
- }
74
- }
75
- None => "" ,
76
- } ,
77
- name : i. 0 . to_string ( ) ,
78
- version : match i. 1 {
79
- JuliaupConfigChannel :: SystemChannel { version } => version. clone ( ) ,
80
- JuliaupConfigChannel :: DirectDownloadChannel {
81
- path : _,
82
- url : _,
83
- local_etag : _,
84
- server_etag : _,
85
- version,
86
- } => {
87
- format ! ( "Development version {version}" )
88
- }
89
- JuliaupConfigChannel :: LinkedChannel { command, args } => {
90
- let mut combined_command = String :: new ( ) ;
91
-
92
- if command. contains ( ' ' ) {
93
- combined_command. push ( '\"' ) ;
94
- combined_command. push_str ( command) ;
95
- combined_command. push ( '\"' ) ;
96
- } else {
97
- combined_command. push_str ( command) ;
98
- }
99
-
100
- if let Some ( args) = args {
101
- for i in args {
102
- combined_command. push ( ' ' ) ;
103
- if i. contains ( ' ' ) {
104
- combined_command. push ( '\"' ) ;
105
- combined_command. push_str ( i) ;
106
- combined_command. push ( '\"' ) ;
107
- } else {
108
- combined_command. push_str ( i) ;
109
- }
110
- }
111
- }
112
- format ! ( "Linked to `{combined_command}`" )
113
- }
114
- JuliaupConfigChannel :: AliasChannel { target, args } => match args {
115
- Some ( args) if !args. is_empty ( ) => {
116
- format ! ( "Alias to `{target}` with args: {:?}" , args)
117
- }
118
- _ => format ! ( "Alias to `{target}`" ) ,
119
- } ,
120
- } ,
121
- update : {
122
- let update_option = match i. 1 {
123
- JuliaupConfigChannel :: SystemChannel { version } => {
124
- match versiondb_data. available_channels . get ( i. 0 ) {
125
- Some ( channel) if & channel. version != version => {
126
- Some ( format ! ( "Update to {} available" , channel. version) )
127
- }
128
- _ => None ,
129
- }
130
- }
131
- JuliaupConfigChannel :: LinkedChannel { .. } => None ,
132
- JuliaupConfigChannel :: AliasChannel { target, args : _ } => {
133
- get_alias_update_info ( target, & config_file, & versiondb_data)
134
- }
135
- JuliaupConfigChannel :: DirectDownloadChannel {
136
- local_etag,
137
- server_etag,
138
- ..
139
- } => ( local_etag != server_etag) . then ( || "Update available" . to_string ( ) ) ,
140
- } ;
141
- update_option. unwrap_or_default ( )
142
- } ,
143
- }
129
+ . sorted_by ( |( channel_name_a, _) , ( channel_name_b, _) | cmp ( channel_name_a, channel_name_b) )
130
+ . map ( |( channel_name, channel) | ChannelRow {
131
+ default : match & config_file. data . default {
132
+ Some ( ref default_value) if channel_name == default_value => "*" ,
133
+ _ => "" ,
134
+ } ,
135
+ name : channel_name. to_string ( ) ,
136
+ version : format_version ( channel) ,
137
+ update : get_update_info ( channel_name, channel, & config_file, & versiondb_data) ,
144
138
} )
145
139
. collect ( ) ;
146
140
0 commit comments