11use crate :: app:: CliApp ;
22use crate :: common:: { display_text, read_upload_file} ;
3+ use crate :: previews:: {
4+ CreateCollectionPreview , DeleteCollectionPreview , UpdateCollectionPreview ,
5+ UploadCollectionCoverPreview ,
6+ } ;
37use clap:: { Args , Subcommand } ;
48use puddle:: models:: collections:: { Collection , CreateCollection , UpdateCollection } ;
59use puddle:: models:: common:: CollectionScope ;
@@ -99,6 +103,13 @@ impl CliApp {
99103 parent : args. parent ,
100104 extra : HashMap :: new ( ) ,
101105 } ;
106+
107+ if self . is_dry_run ( ) {
108+ println ! ( "{}" , CreateCollectionPreview :: new( & payload) ) ;
109+
110+ return Ok ( ( ) ) ;
111+ }
112+
102113 let response = self . client . collections ( ) . create ( & payload) . await ?;
103114 print_collection_detail ( & response. data ) ;
104115
@@ -114,6 +125,23 @@ impl CliApp {
114125 parent : args. parent ,
115126 extra : HashMap :: new ( ) ,
116127 } ;
128+
129+ if self . is_dry_run ( ) {
130+ let existing_collection = self
131+ . client
132+ . collections ( )
133+ . get ( CollectionScope :: from ( args. id ) )
134+ . await ?
135+ . data ;
136+
137+ println ! (
138+ "{}" ,
139+ UpdateCollectionPreview :: new( & existing_collection, & payload)
140+ ) ;
141+
142+ return Ok ( ( ) ) ;
143+ }
144+
117145 let response = self . client . collections ( ) . update ( args. id , & payload) . await ?;
118146 print_collection_detail ( & response. data ) ;
119147
@@ -124,6 +152,19 @@ impl CliApp {
124152 & self ,
125153 args : DeleteCollectionArgs ,
126154 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
155+ if self . is_dry_run ( ) {
156+ let existing_collection = self
157+ . client
158+ . collections ( )
159+ . get ( CollectionScope :: from ( args. id ) )
160+ . await ?
161+ . data ;
162+
163+ println ! ( "{}" , DeleteCollectionPreview :: new( & existing_collection) ) ;
164+
165+ return Ok ( ( ) ) ;
166+ }
167+
127168 let response = self . client . collections ( ) . delete ( args. id ) . await ?;
128169 println ! ( "deleted: {}" , response. data) ;
129170
@@ -134,6 +175,23 @@ impl CliApp {
134175 & self ,
135176 args : UploadCollectionCoverArgs ,
136177 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
178+ if self . is_dry_run ( ) {
179+ let _ = read_upload_file ( & args. path ) ?;
180+ let existing_collection = self
181+ . client
182+ . collections ( )
183+ . get ( CollectionScope :: from ( args. id ) )
184+ . await ?
185+ . data ;
186+
187+ println ! (
188+ "{}" ,
189+ UploadCollectionCoverPreview :: new( & existing_collection, & args. path)
190+ ) ;
191+
192+ return Ok ( ( ) ) ;
193+ }
194+
137195 let ( bytes, mime, file_name) = read_upload_file ( & args. path ) ?;
138196 let response = self
139197 . client
@@ -189,7 +247,6 @@ fn format_collection_summary(item: &Collection) -> String {
189247
190248 parts. join ( " | " )
191249}
192-
193250#[ cfg( test) ]
194251mod tests {
195252 use super :: * ;
0 commit comments