@@ -19,10 +19,10 @@ pub(crate) fn get_hosts_output(hosts: Vec<Host>) -> CommandOutput {
1919 CommandOutput :: new ( hosts_table ( hosts) , map)
2020}
2121
22- pub ( crate ) fn get_host_inventory_output ( inv : HostInventory ) -> CommandOutput {
22+ pub ( crate ) fn get_host_inventories_output ( invs : Vec < HostInventory > ) -> CommandOutput {
2323 let mut map = HashMap :: new ( ) ;
24- map. insert ( "inventory " . to_string ( ) , json ! ( inv ) ) ;
25- CommandOutput :: new ( host_inventory_table ( inv ) , map)
24+ map. insert ( "inventories " . to_string ( ) , json ! ( invs ) ) ;
25+ CommandOutput :: new ( host_inventories_table ( invs ) , map)
2626}
2727
2828pub ( crate ) fn get_claims_output ( claims : Vec < HashMap < String , String > > ) -> CommandOutput {
@@ -96,90 +96,97 @@ pub(crate) fn hosts_table(hosts: Vec<Host>) -> String {
9696}
9797
9898/// Helper function to transform a HostInventory into a table string for printing
99- pub ( crate ) fn host_inventory_table ( inv : HostInventory ) -> String {
99+ pub ( crate ) fn host_inventories_table ( invs : Vec < HostInventory > ) -> String {
100100 let mut table = Table :: new ( ) ;
101101 crate :: util:: configure_table_style ( & mut table) ;
102102
103- table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
104- format!( "Host Inventory ({})" , inv. host_id) ,
105- 4 ,
106- Alignment :: Center ,
107- ) ] ) ) ;
108-
109- if !inv. labels . is_empty ( ) {
103+ invs. into_iter ( ) . for_each ( |inv| {
110104 table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
111- "" ,
105+ format! ( "Host Inventory ({})" , inv . host_id ) ,
112106 4 ,
113107 Alignment :: Center ,
114108 ) ] ) ) ;
115- inv. labels . iter ( ) . for_each ( |( k, v) | {
116- table. add_row ( Row :: new ( vec ! [
117- TableCell :: new_with_alignment( k, 2 , Alignment :: Left ) ,
118- TableCell :: new_with_alignment( v, 2 , Alignment :: Left ) ,
119- ] ) )
120- } ) ;
121- } else {
109+
110+ if !inv. labels . is_empty ( ) {
111+ table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
112+ "" ,
113+ 4 ,
114+ Alignment :: Center ,
115+ ) ] ) ) ;
116+ inv. labels . iter ( ) . for_each ( |( k, v) | {
117+ table. add_row ( Row :: new ( vec ! [
118+ TableCell :: new_with_alignment( k, 2 , Alignment :: Left ) ,
119+ TableCell :: new_with_alignment( v, 2 , Alignment :: Left ) ,
120+ ] ) )
121+ } ) ;
122+ } else {
123+ table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
124+ "No labels present" ,
125+ 4 ,
126+ Alignment :: Center ,
127+ ) ] ) ) ;
128+ }
129+
122130 table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
123- "No labels present " ,
131+ "" ,
124132 4 ,
125133 Alignment :: Center ,
126134 ) ] ) ) ;
127- }
128-
129- table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
130- "" ,
131- 4 ,
132- Alignment :: Center ,
133- ) ] ) ) ;
134- if !inv. actors . is_empty ( ) {
135- table. add_row ( Row :: new ( vec ! [
136- TableCell :: new_with_alignment( "Actor ID" , 1 , Alignment :: Left ) ,
137- TableCell :: new_with_alignment( "Name" , 1 , Alignment :: Left ) ,
138- TableCell :: new_with_alignment( "Image Reference" , 2 , Alignment :: Left ) ,
139- ] ) ) ;
140- inv. actors . iter ( ) . for_each ( |a| {
141- let a = a. clone ( ) ;
135+ if !inv. actors . is_empty ( ) {
142136 table. add_row ( Row :: new ( vec ! [
143- TableCell :: new_with_alignment( a. id, 1 , Alignment :: Left ) ,
144- TableCell :: new_with_alignment( format_optional( a. name) , 1 , Alignment :: Left ) ,
145- TableCell :: new_with_alignment( format_optional( a. image_ref) , 2 , Alignment :: Left ) ,
146- ] ) )
147- } ) ;
148- } else {
137+ TableCell :: new_with_alignment( "Actor ID" , 1 , Alignment :: Left ) ,
138+ TableCell :: new_with_alignment( "Name" , 1 , Alignment :: Left ) ,
139+ TableCell :: new_with_alignment( "Image Reference" , 2 , Alignment :: Left ) ,
140+ ] ) ) ;
141+ inv. actors . iter ( ) . for_each ( |a| {
142+ let a = a. clone ( ) ;
143+ table. add_row ( Row :: new ( vec ! [
144+ TableCell :: new_with_alignment( a. id, 1 , Alignment :: Left ) ,
145+ TableCell :: new_with_alignment( format_optional( a. name) , 1 , Alignment :: Left ) ,
146+ TableCell :: new_with_alignment( format_optional( a. image_ref) , 2 , Alignment :: Left ) ,
147+ ] ) )
148+ } ) ;
149+ } else {
150+ table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
151+ "No actors found" ,
152+ 4 ,
153+ Alignment :: Left ,
154+ ) ] ) ) ;
155+ }
149156 table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
150- "No actors found " ,
157+ "" ,
151158 4 ,
152159 Alignment :: Left ,
153160 ) ] ) ) ;
154- }
155- table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
156- "" ,
157- 4 ,
158- Alignment :: Left ,
159- ) ] ) ) ;
160- if !inv. providers . is_empty ( ) {
161- table. add_row ( Row :: new ( vec ! [
162- TableCell :: new_with_alignment( "Provider ID" , 1 , Alignment :: Left ) ,
163- TableCell :: new_with_alignment( "Name" , 1 , Alignment :: Left ) ,
164- TableCell :: new_with_alignment( "Link Name" , 1 , Alignment :: Left ) ,
165- TableCell :: new_with_alignment( "Image Reference" , 1 , Alignment :: Left ) ,
166- ] ) ) ;
167- inv. providers . iter ( ) . for_each ( |p| {
168- let p = p. clone ( ) ;
161+ if !inv. providers . is_empty ( ) {
169162 table. add_row ( Row :: new ( vec ! [
170- TableCell :: new_with_alignment( p. id, 1 , Alignment :: Left ) ,
171- TableCell :: new_with_alignment( format_optional( p. name) , 1 , Alignment :: Left ) ,
172- TableCell :: new_with_alignment( p. link_name, 1 , Alignment :: Left ) ,
173- TableCell :: new_with_alignment( format_optional( p. image_ref) , 1 , Alignment :: Left ) ,
174- ] ) )
175- } ) ;
176- } else {
163+ TableCell :: new_with_alignment( "Provider ID" , 1 , Alignment :: Left ) ,
164+ TableCell :: new_with_alignment( "Name" , 1 , Alignment :: Left ) ,
165+ TableCell :: new_with_alignment( "Link Name" , 1 , Alignment :: Left ) ,
166+ TableCell :: new_with_alignment( "Image Reference" , 1 , Alignment :: Left ) ,
167+ ] ) ) ;
168+ inv. providers . iter ( ) . for_each ( |p| {
169+ let p = p. clone ( ) ;
170+ table. add_row ( Row :: new ( vec ! [
171+ TableCell :: new_with_alignment( p. id, 1 , Alignment :: Left ) ,
172+ TableCell :: new_with_alignment( format_optional( p. name) , 1 , Alignment :: Left ) ,
173+ TableCell :: new_with_alignment( p. link_name, 1 , Alignment :: Left ) ,
174+ TableCell :: new_with_alignment( format_optional( p. image_ref) , 1 , Alignment :: Left ) ,
175+ ] ) )
176+ } ) ;
177+ } else {
178+ table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
179+ "No providers found" ,
180+ 4 ,
181+ Alignment :: Left ,
182+ ) ] ) ) ;
183+ }
177184 table. add_row ( Row :: new ( vec ! [ TableCell :: new_with_alignment(
178- "No providers found " ,
185+ "" ,
179186 4 ,
180187 Alignment :: Left ,
181188 ) ] ) ) ;
182- }
189+ } ) ;
183190
184191 table. render ( )
185192}
0 commit comments