@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
2
2
use std:: fmt:: { self , Debug , Display } ;
3
3
use std:: io;
4
4
5
+ use crate :: cli:: FormatType ;
5
6
use crate :: command:: supergraph:: compose:: CompositionOutput ;
6
7
use crate :: utils:: table:: { self , row} ;
7
8
use crate :: RoverError ;
@@ -27,7 +28,7 @@ use termimad::MadSkin;
27
28
/// RoverOutput defines all of the different types of data that are printed
28
29
/// to `stdout`. Every one of Rover's commands should return `saucer::Result<RoverOutput>`
29
30
/// If the command needs to output some type of data, it should be structured
30
- /// in this enum, and its print logic should be handled in `RoverOutput::print `
31
+ /// in this enum, and its print logic should be handled in `RoverOutput::get_stdout `
31
32
///
32
33
/// Not all commands will output machine readable information, and those should
33
34
/// return `Ok(RoverOutput::EmptySuccess)`. If a new command is added and it needs to
@@ -78,8 +79,8 @@ pub enum RoverOutput {
78
79
}
79
80
80
81
impl RoverOutput {
81
- pub fn print ( & self ) -> io:: Result < ( ) > {
82
- match self {
82
+ pub fn get_stdout ( & self ) -> io:: Result < Option < String > > {
83
+ Ok ( match self {
83
84
RoverOutput :: DocsList ( shortlinks) => {
84
85
stderrln ! (
85
86
"You can open any of these documentation pages by running {}.\n " ,
@@ -92,14 +93,14 @@ impl RoverOutput {
92
93
for ( shortlink_slug, shortlink_description) in shortlinks {
93
94
table. add_row ( row ! [ shortlink_slug, shortlink_description] ) ;
94
95
}
95
- stdoutln ! ( "{}" , table) ? ;
96
+ Some ( format ! ( "{}" , table) )
96
97
}
97
98
RoverOutput :: FetchResponse ( fetch_response) => {
98
99
match fetch_response. sdl . r#type {
99
100
SdlType :: Graph | SdlType :: Subgraph { .. } => print_descriptor ( "SDL" ) ?,
100
101
SdlType :: Supergraph => print_descriptor ( "Supergraph SDL" ) ?,
101
102
}
102
- print_content ( & fetch_response. sdl . contents ) ? ;
103
+ Some ( format ! ( "{}" , & fetch_response. sdl. contents) )
103
104
}
104
105
RoverOutput :: GraphPublishResponse {
105
106
graph_ref,
@@ -112,7 +113,7 @@ impl RoverOutput {
112
113
publish_response. change_summary
113
114
) ?;
114
115
print_one_line_descriptor ( "Schema Hash" ) ?;
115
- print_content ( & publish_response. api_schema_hash ) ? ;
116
+ Some ( format ! ( "{}" , && publish_response. api_schema_hash) )
116
117
}
117
118
RoverOutput :: SubgraphPublishResponse {
118
119
graph_ref,
@@ -147,6 +148,7 @@ impl RoverOutput {
147
148
stderrln ! ( "{} The following build errors occurred:" , warn_prefix) ?;
148
149
stderrln ! ( "{}" , & publish_response. build_errors) ?;
149
150
}
151
+ None
150
152
}
151
153
RoverOutput :: SubgraphDeleteResponse {
152
154
graph_ref,
@@ -196,10 +198,11 @@ impl RoverOutput {
196
198
stderrln ! ( "{}" , & delete_response. build_errors) ?;
197
199
}
198
200
}
201
+ None
199
202
}
200
203
RoverOutput :: CoreSchema ( csdl) => {
201
204
print_descriptor ( "CoreSchema" ) ?;
202
- print_content ( csdl) ? ;
205
+ Some ( format ! ( "{}" , csdl) )
203
206
}
204
207
RoverOutput :: CompositionResult ( composition_output) => {
205
208
let warn_prefix = Style :: HintPrefix . paint ( "HINT:" ) ;
@@ -213,7 +216,7 @@ impl RoverOutput {
213
216
stderrln ! ( "{}" , hints_string) ?;
214
217
215
218
print_descriptor ( "CoreSchema" ) ?;
216
- print_content ( & composition_output. supergraph_sdl ) ? ;
219
+ Some ( format ! ( "{}" , & composition_output. supergraph_sdl) )
217
220
}
218
221
RoverOutput :: SubgraphList ( details) => {
219
222
let mut table = table:: get_table ( ) ;
@@ -240,13 +243,10 @@ impl RoverOutput {
240
243
241
244
table. add_row ( row ! [ subgraph. name, url, formatted_updated_at] ) ;
242
245
}
243
-
244
- stdoutln ! ( "{}" , table) ?;
245
- stdoutln ! (
246
- "View full details at {}/graph/{}/service-list" ,
247
- details. root_url,
248
- details. graph_ref. name
249
- ) ?;
246
+ Some ( format ! (
247
+ "{}/n View full details at {}/graph/{}/service-list" ,
248
+ table, details. root_url, details. graph_ref. name
249
+ ) )
250
250
}
251
251
RoverOutput :: TemplateList ( templates) => {
252
252
let mut table = table:: get_table ( ) ;
@@ -263,78 +263,72 @@ impl RoverOutput {
263
263
] ) ;
264
264
}
265
265
266
- stdoutln ! ( "{}" , table) ? ;
266
+ Some ( format ! ( "{}" , table) )
267
267
}
268
268
RoverOutput :: TemplateUseSuccess { template, path } => {
269
269
print_descriptor ( "Project generated" ) ?;
270
- stdoutln ! (
271
- "Successfully created a new project from the '{template_id}' template in {path}" ,
272
- template_id = Style :: Command . paint( template. id) ,
273
- path = Style :: Path . paint( path. as_str( ) )
274
- ) ?;
275
- stdoutln ! (
276
- "Read the generated '{readme}' file for next steps." ,
277
- readme = Style :: Path . paint( "README.md" )
278
- ) ?;
270
+ let template_id = Style :: Command . paint ( template. id ) ;
271
+ let path = Style :: Path . paint ( path. as_str ( ) ) ;
272
+ let readme = Style :: Path . paint ( "README.md" ) ;
279
273
let forum_call_to_action = Style :: CallToAction . paint (
280
274
"Have a question or suggestion about templates? Let us know at \
281
275
https://community.apollographql.com",
282
276
) ;
283
- stdoutln ! ( "{}" , forum_call_to_action) ?;
277
+ Some ( format ! ( "Successfully created a new project from the '{}' template in {}/n Read the generated '{}' file for next steps./n{}" ,
278
+ template_id,
279
+ path,
280
+ readme,
281
+ forum_call_to_action) )
284
282
}
285
283
RoverOutput :: CheckResponse ( check_response) => {
286
284
print_descriptor ( "Check Result" ) ?;
287
- print_content ( check_response. get_table ( ) ) ? ;
285
+ Some ( format ! ( "{}" , check_response. get_table( ) ) )
288
286
}
289
287
RoverOutput :: AsyncCheckResponse ( check_response) => {
290
288
print_descriptor ( "Check Started" ) ?;
291
- stdoutln ! (
292
- "Check successfully started with workflow ID: {}" ,
293
- check_response. workflow_id,
294
- ) ?;
295
- stdoutln ! ( "View full details at {}" , check_response. target_url) ?;
289
+ Some ( format ! (
290
+ "Check successfully started with workflow ID: {}/nView full details at {}" ,
291
+ check_response. workflow_id, check_response. target_url
292
+ ) )
296
293
}
297
294
RoverOutput :: Profiles ( profiles) => {
298
295
if profiles. is_empty ( ) {
299
296
stderrln ! ( "No profiles found." ) ?;
300
297
} else {
301
298
print_descriptor ( "Profiles" ) ?;
302
299
}
303
-
304
- for profile in profiles {
305
- stdoutln ! ( "{}" , profile) ?;
306
- }
300
+ Some ( format ! ( "{}" , profiles. join( "\n " ) ) )
307
301
}
308
302
RoverOutput :: Introspection ( introspection_response) => {
309
303
print_descriptor ( "Introspection Response" ) ?;
310
- print_content ( introspection_response) ? ;
304
+ Some ( format ! ( "{}" , introspection_response) )
311
305
}
312
306
RoverOutput :: ErrorExplanation ( explanation) => {
313
307
// underline bolded md
314
308
let mut skin = MadSkin :: default ( ) ;
315
309
skin. bold . add_attr ( Underlined ) ;
316
310
317
- stdoutln ! ( "{}" , skin. inline( explanation) ) ? ;
311
+ Some ( format ! ( "{}" , skin. inline( explanation) ) )
318
312
}
319
313
RoverOutput :: ReadmeFetchResponse {
320
314
graph_ref : _,
321
315
content,
322
316
last_updated_time : _,
323
317
} => {
324
318
print_descriptor ( "Readme" ) ?;
325
- print_content ( content) ? ;
319
+ Some ( format ! ( "{}" , content) )
326
320
}
327
321
RoverOutput :: ReadmePublishResponse {
328
322
graph_ref,
329
323
new_content : _,
330
324
last_updated_time : _,
331
325
} => {
332
326
stderrln ! ( "Readme for {} published successfully" , graph_ref, ) ?;
327
+ None
333
328
}
334
- RoverOutput :: EmptySuccess => ( ) ,
335
- } ;
336
- Ok ( ( ) )
337
- }
329
+ RoverOutput :: EmptySuccess => None ,
330
+ }
331
+ ) }
338
332
339
333
pub ( crate ) fn get_internal_data_json ( & self ) -> Value {
340
334
match self {
0 commit comments