1
- use crate :: commands:: { client_and_app_id, create_cloud_client, CommonArgs } ;
1
+ use crate :: commands:: { apps_output :: AppInfo , client_and_app_id, create_cloud_client, CommonArgs } ;
2
2
use anyhow:: { Context , Result } ;
3
3
use clap:: Parser ;
4
4
use cloud:: { CloudClientInterface , DEFAULT_APPLIST_PAGE_SIZE } ;
5
- use cloud_openapi:: models:: { AppItem , AppItemPage , ValidationStatus } ;
5
+ use cloud_openapi:: models:: { AppItem , ValidationStatus } ;
6
+
7
+ use super :: apps_output:: { print_app_info, print_app_list, OutputFormat } ;
6
8
7
9
#[ derive( Parser , Debug ) ]
8
10
#[ clap( about = "Manage applications deployed to Fermyon Cloud" ) ]
@@ -19,6 +21,9 @@ pub enum AppsCommand {
19
21
pub struct ListCommand {
20
22
#[ clap( flatten) ]
21
23
common : CommonArgs ,
24
+ /// Desired output format
25
+ #[ clap( value_enum, long = "format" , default_value = "plain" ) ]
26
+ format : OutputFormat ,
22
27
}
23
28
24
29
#[ derive( Parser , Debug ) ]
@@ -35,6 +40,9 @@ pub struct InfoCommand {
35
40
pub app : String ,
36
41
#[ clap( flatten) ]
37
42
common : CommonArgs ,
43
+ /// Desired output format
44
+ #[ clap( value_enum, long = "format" , default_value = "plain" ) ]
45
+ format : OutputFormat ,
38
46
}
39
47
40
48
impl AppsCommand {
@@ -51,19 +59,21 @@ impl ListCommand {
51
59
pub async fn run ( self ) -> Result < ( ) > {
52
60
let client = create_cloud_client ( self . common . deployment_env_id . as_deref ( ) ) . await ?;
53
61
let mut app_list_page = client. list_apps ( DEFAULT_APPLIST_PAGE_SIZE , None ) . await ?;
54
- if app_list_page . total_items <= 0 {
55
- eprintln ! ( "No applications found" ) ;
56
- } else {
57
- print_app_list ( & app_list_page ) ;
58
- let mut page_index = 1 ;
59
- while !app_list_page. is_last_page {
60
- app_list_page = client
61
- . list_apps ( DEFAULT_APPLIST_PAGE_SIZE , Some ( page_index) )
62
- . await ?;
63
- print_app_list ( & app_list_page) ;
64
- page_index += 1 ;
62
+ let mut apps : Vec < String > = vec ! [ ] ;
63
+ let mut page_index = 1 ;
64
+ for app in app_list_page . items {
65
+ apps . push ( app . name . clone ( ) ) ;
66
+ }
67
+ while !app_list_page. is_last_page {
68
+ app_list_page = client
69
+ . list_apps ( DEFAULT_APPLIST_PAGE_SIZE , Some ( page_index) )
70
+ . await ?;
71
+ for app in app_list_page. items {
72
+ apps . push ( app . name . clone ( ) ) ;
65
73
}
74
+ page_index += 1 ;
66
75
}
76
+ print_app_list ( apps, self . format ) ;
67
77
Ok ( ( ) )
68
78
}
69
79
}
@@ -92,13 +102,14 @@ impl InfoCommand {
92
102
93
103
let ( current_domain, in_progress_domain) = domains_current_and_in_progress ( & app) ;
94
104
95
- println ! ( "Name: {}" , & app . name ) ;
96
- print_if_present ( "Description: " , app. description . as_ref ( ) ) ;
97
- print_if_present ( "URL: https://" , current_domain ) ;
98
- if let Some ( domain ) = in_progress_domain {
99
- println ! ( "Validation for {} is in progress" , domain ) ;
100
- } ;
105
+ let info = AppInfo :: new (
106
+ app. name . clone ( ) ,
107
+ app . description . clone ( ) ,
108
+ current_domain . cloned ( ) ,
109
+ in_progress_domain . is_none ( ) ,
110
+ ) ;
101
111
112
+ print_app_info ( info, self . format ) ;
102
113
Ok ( ( ) )
103
114
}
104
115
}
@@ -116,17 +127,3 @@ fn domains_current_and_in_progress(app: &AppItem) -> (Option<&String>, Option<&S
116
127
None => ( Some ( auto_domain) , None ) ,
117
128
}
118
129
}
119
-
120
- fn print_if_present ( prefix : & str , value : Option < & String > ) {
121
- if let Some ( val) = value {
122
- if !val. is_empty ( ) {
123
- println ! ( "{prefix}{val}" ) ;
124
- }
125
- }
126
- }
127
-
128
- fn print_app_list ( page : & AppItemPage ) {
129
- for app in & page. items {
130
- println ! ( "{}" , app. name) ;
131
- }
132
- }
0 commit comments