@@ -8,70 +8,18 @@ use minijinja::{context, Environment};
8
8
use crate :: models:: prelude:: { ModelMetadata , V1AlphaDoctorGroup } ;
9
9
use crate :: models:: HelpMetadata ;
10
10
use crate :: prelude:: { DoctorGroupActionSpec , DoctorInclude } ;
11
- use crate :: shared:: models:: internal:: extract_command_path ;
11
+ use crate :: shared:: models:: internal:: { DoctorCommand , DoctorFix , DoctorFixPrompt } ;
12
12
13
13
#[ derive( Debug , PartialEq , Clone , Builder ) ]
14
14
#[ builder( setter( into) ) ]
15
15
pub struct DoctorGroupAction {
16
16
pub name : String ,
17
17
pub description : String ,
18
- pub fix : DoctorGroupActionFix ,
18
+ pub fix : DoctorFix ,
19
19
pub check : DoctorGroupActionCheck ,
20
20
pub required : bool ,
21
21
}
22
22
23
- #[ derive( Debug , PartialEq , Clone , Builder ) ]
24
- #[ builder( setter( into) ) ]
25
- pub struct DoctorGroupActionFix {
26
- #[ builder( default ) ]
27
- pub command : Option < DoctorGroupActionCommand > ,
28
- #[ builder( default ) ]
29
- pub help_text : Option < String > ,
30
- #[ builder( default ) ]
31
- pub help_url : Option < String > ,
32
- #[ builder( default ) ]
33
- pub prompt : Option < DoctorGroupActionFixPrompt > ,
34
- }
35
-
36
- #[ derive( Debug , PartialEq , Clone , Builder ) ]
37
- #[ builder( setter( into) ) ]
38
- pub struct DoctorGroupActionFixPrompt {
39
- #[ builder( default ) ]
40
- pub text : String ,
41
- #[ builder( default ) ]
42
- pub extra_context : Option < String > ,
43
- }
44
-
45
- impl DoctorGroupAction {
46
- pub fn make_from (
47
- name : & str ,
48
- description : & str ,
49
- prompt : Option < DoctorGroupActionFixPrompt > ,
50
- fix_command : Option < Vec < & str > > ,
51
- check_path : Option < ( & str , Vec < & str > ) > ,
52
- check_command : Option < Vec < & str > > ,
53
- ) -> Self {
54
- Self {
55
- required : true ,
56
- name : name. to_string ( ) ,
57
- description : description. to_string ( ) ,
58
- fix : DoctorGroupActionFix {
59
- command : fix_command. map ( DoctorGroupActionCommand :: from) ,
60
- help_text : None ,
61
- help_url : None ,
62
- prompt,
63
- } ,
64
- check : DoctorGroupActionCheck {
65
- command : check_command. map ( DoctorGroupActionCommand :: from) ,
66
- files : check_path. map ( |( base, paths) | DoctorGroupCachePath {
67
- base_path : PathBuf :: from ( base) ,
68
- paths : crate :: shared:: convert_to_string ( paths) ,
69
- } ) ,
70
- } ,
71
- }
72
- }
73
- }
74
-
75
23
#[ derive( Debug , PartialEq , Clone , Builder ) ]
76
24
#[ builder( setter( into) ) ]
77
25
pub struct DoctorGroupCachePath {
@@ -94,40 +42,10 @@ impl From<(&str, Vec<&str>)> for DoctorGroupCachePath {
94
42
#[ derive( Debug , PartialEq , Clone , Builder ) ]
95
43
#[ builder( setter( into) ) ]
96
44
pub struct DoctorGroupActionCheck {
97
- pub command : Option < DoctorGroupActionCommand > ,
45
+ pub command : Option < DoctorCommand > ,
98
46
pub files : Option < DoctorGroupCachePath > ,
99
47
}
100
48
101
- #[ derive( Debug , PartialEq , Clone , Builder ) ]
102
- #[ builder( setter( into) ) ]
103
- pub struct DoctorGroupActionCommand {
104
- pub commands : Vec < String > ,
105
- }
106
-
107
- impl From < Vec < & str > > for DoctorGroupActionCommand {
108
- fn from ( value : Vec < & str > ) -> Self {
109
- let commands = value. iter ( ) . map ( |x| x. to_string ( ) ) . collect ( ) ;
110
- Self { commands }
111
- }
112
- }
113
-
114
- impl < T > From < ( & Path , Vec < T > ) > for DoctorGroupActionCommand
115
- where
116
- String : for < ' a > From < & ' a T > ,
117
- {
118
- fn from ( ( base_path, command_strings) : ( & Path , Vec < T > ) ) -> Self {
119
- let commands = command_strings
120
- . iter ( )
121
- . map ( |s| {
122
- let exec: String = s. into ( ) ;
123
- extract_command_path ( base_path, & exec)
124
- } )
125
- . collect ( ) ;
126
-
127
- DoctorGroupActionCommand { commands }
128
- }
129
- }
130
-
131
49
#[ derive( Debug , PartialEq , Clone , Builder ) ]
132
50
#[ builder( setter( into) ) ]
133
51
pub struct DoctorGroup {
@@ -204,10 +122,7 @@ fn parse_action(
204
122
for command in & fix. commands {
205
123
templated_commands. push ( substitute_templates ( & working_dir, command) ?) ;
206
124
}
207
- Some ( DoctorGroupActionCommand :: from ( (
208
- containing_dir,
209
- templated_commands,
210
- ) ) )
125
+ Some ( DoctorCommand :: from ( ( containing_dir, templated_commands) ) )
211
126
} else {
212
127
None
213
128
} ;
@@ -217,10 +132,7 @@ fn parse_action(
217
132
for command in check {
218
133
templated_commands. push ( substitute_templates ( & working_dir, command) ?) ;
219
134
}
220
- Some ( DoctorGroupActionCommand :: from ( (
221
- containing_dir,
222
- templated_commands,
223
- ) ) )
135
+ Some ( DoctorCommand :: from ( ( containing_dir, templated_commands) ) )
224
136
} else {
225
137
None
226
138
} ;
@@ -231,14 +143,12 @@ fn parse_action(
231
143
description : spec_action
232
144
. description
233
145
. unwrap_or_else ( || "default" . to_string ( ) ) ,
234
- fix : DoctorGroupActionFix {
146
+ fix : DoctorFix {
235
147
command : fix_command,
236
- prompt : spec_action. fix . and_then ( |fix| fix. prompt ) . map ( |p| {
237
- DoctorGroupActionFixPrompt {
238
- text : p. text ,
239
- extra_context : p. extra_context ,
240
- }
241
- } ) ,
148
+ prompt : spec_action
149
+ . fix
150
+ . and_then ( |fix| fix. prompt )
151
+ . map ( DoctorFixPrompt :: from) ,
242
152
help_text,
243
153
help_url,
244
154
} ,
@@ -261,7 +171,7 @@ mod tests {
261
171
262
172
use crate :: shared:: models:: parse_models_from_string;
263
173
use crate :: shared:: models:: prelude:: {
264
- DoctorGroupAction , DoctorGroupActionCheck , DoctorGroupActionCommand , DoctorGroupActionFix ,
174
+ DoctorCommand , DoctorFix , DoctorGroupAction , DoctorGroupActionCheck ,
265
175
} ;
266
176
use crate :: shared:: prelude:: DoctorGroupCachePath ;
267
177
@@ -290,18 +200,14 @@ mod tests {
290
200
name: "1" . to_string( ) ,
291
201
required: false ,
292
202
description: "foo1" . to_string( ) ,
293
- fix: DoctorGroupActionFix {
294
- command: Some ( DoctorGroupActionCommand :: from( vec![
295
- "/foo/bar/.scope/fix1.sh"
296
- ] ) ) ,
203
+ fix: DoctorFix {
204
+ command: Some ( DoctorCommand :: from( vec![ "/foo/bar/.scope/fix1.sh" ] ) ) ,
297
205
prompt: None ,
298
206
help_text: Some ( "There is a good way to fix this, maybe..." . to_string( ) ) ,
299
207
help_url: Some ( "https://go.example.com/fixit" . to_string( ) ) ,
300
208
} ,
301
209
check: DoctorGroupActionCheck {
302
- command: Some ( DoctorGroupActionCommand :: from( vec![
303
- "/foo/bar/.scope/foo1.sh"
304
- ] ) ) ,
210
+ command: Some ( DoctorCommand :: from( vec![ "/foo/bar/.scope/foo1.sh" ] ) ) ,
305
211
files: Some ( DoctorGroupCachePath :: from( (
306
212
"/foo/bar" ,
307
213
vec![ "flig/bar/**/*" ]
@@ -315,14 +221,14 @@ mod tests {
315
221
name: "2" . to_string( ) ,
316
222
required: true ,
317
223
description: "foo2" . to_string( ) ,
318
- fix: DoctorGroupActionFix {
224
+ fix: DoctorFix {
319
225
command: None ,
320
226
help_text: None ,
321
227
help_url: None ,
322
228
prompt: None ,
323
229
} ,
324
230
check: DoctorGroupActionCheck {
325
- command: Some ( DoctorGroupActionCommand :: from( vec![ "sleep infinity" ] ) ) ,
231
+ command: Some ( DoctorCommand :: from( vec![ "sleep infinity" ] ) ) ,
326
232
files: Some ( DoctorGroupCachePath :: from( ( "/foo/bar" , vec![ "*/*.txt" ] ) ) )
327
233
}
328
234
}
0 commit comments