@@ -18,7 +18,8 @@ mod dir_helpers;
18
18
mod filecontent_helper;
19
19
20
20
const EXIT_SUCCESS : i32 = 0 ;
21
- const EXIT_INVALID_INPUT : i32 = 2 ;
21
+ const EXIT_INVALID_INPUT : i32 = 1 ;
22
+ const EXIT_JSON_SERIALIZATION_FAILED : i32 = 2 ;
22
23
23
24
fn main ( ) {
24
25
let args = Args :: parse ( ) ;
@@ -30,9 +31,21 @@ fn main() {
30
31
debug ! ( "Getting file at path: {}" , input) ;
31
32
match parse_file ( input) {
32
33
Some ( parsed_file) => {
33
- let file = get_file ( & parsed_file) . unwrap ( ) ;
34
- let json = serde_json:: to_string ( & file) . unwrap ( ) ;
35
- println ! ( "{}" , json) ;
34
+ match get_file ( & parsed_file) {
35
+ Ok ( file) => {
36
+ match serde_json:: to_string ( & file) {
37
+ Ok ( json) => println ! ( "{}" , json) ,
38
+ Err ( e) => {
39
+ error ! ( "Failed to serialize file: {}" , e) ;
40
+ exit ( EXIT_JSON_SERIALIZATION_FAILED ) ;
41
+ }
42
+ }
43
+ }
44
+ Err ( e) => {
45
+ error ! ( "Failed to get file: {}" , e) ;
46
+ exit ( EXIT_INVALID_INPUT ) ;
47
+ }
48
+ }
36
49
}
37
50
None => {
38
51
error ! ( "Invalid input for file." ) ;
@@ -44,9 +57,21 @@ fn main() {
44
57
debug ! ( "Getting directory at path: {}" , input) ;
45
58
match parse_directory ( input) {
46
59
Some ( parsed_directory) => {
47
- let dir = get_dir ( & parsed_directory) . unwrap ( ) ;
48
- let json = serde_json:: to_string ( & dir) . unwrap ( ) ;
49
- println ! ( "{}" , json) ;
60
+ match get_dir ( & parsed_directory) {
61
+ Ok ( dir) => {
62
+ match serde_json:: to_string ( & dir) {
63
+ Ok ( json) => println ! ( "{}" , json) ,
64
+ Err ( e) => {
65
+ error ! ( "Failed to serialize directory: {}" , e) ;
66
+ exit ( EXIT_JSON_SERIALIZATION_FAILED ) ;
67
+ }
68
+ }
69
+ }
70
+ Err ( e) => {
71
+ error ! ( "Failed to get directory: {}" , e) ;
72
+ exit ( EXIT_INVALID_INPUT ) ;
73
+ }
74
+ }
50
75
}
51
76
None => {
52
77
error ! ( "Invalid input for directory." ) ;
@@ -58,9 +83,21 @@ fn main() {
58
83
debug ! ( "Getting file content at path: {}" , input) ;
59
84
match parse_filecontent ( input) {
60
85
Some ( parsed_filecontent) => {
61
- let filecontent = get_file_content ( & parsed_filecontent) . unwrap ( ) ;
62
- let json = serde_json:: to_string ( & filecontent) . unwrap ( ) ;
63
- println ! ( "{}" , json) ;
86
+ match get_file_content ( & parsed_filecontent) {
87
+ Ok ( filecontent) => {
88
+ match serde_json:: to_string ( & filecontent) {
89
+ Ok ( json) => println ! ( "{}" , json) ,
90
+ Err ( e) => {
91
+ error ! ( "Failed to serialize file content: {}" , e) ;
92
+ exit ( EXIT_JSON_SERIALIZATION_FAILED ) ;
93
+ }
94
+ }
95
+ }
96
+ Err ( e) => {
97
+ error ! ( "Failed to get file content: {}" , e) ;
98
+ exit ( EXIT_INVALID_INPUT ) ;
99
+ }
100
+ }
64
101
}
65
102
None => {
66
103
error ! ( "Invalid input for file content." ) ;
@@ -79,9 +116,21 @@ fn main() {
79
116
debug ! ( "Deleting file at path: {}" , input) ;
80
117
match parse_file ( input) {
81
118
Some ( parsed_file) => {
82
- let file = delete_file ( & parsed_file) . unwrap ( ) ;
83
- let json = serde_json:: to_string ( & file) . unwrap ( ) ;
84
- println ! ( "{}" , json) ;
119
+ match delete_file ( & parsed_file) {
120
+ Ok ( file) => {
121
+ match serde_json:: to_string ( & file) {
122
+ Ok ( json) => println ! ( "{}" , json) ,
123
+ Err ( e) => {
124
+ error ! ( "Failed to serialize file: {}" , e) ;
125
+ exit ( EXIT_INVALID_INPUT ) ;
126
+ }
127
+ }
128
+ }
129
+ Err ( e) => {
130
+ error ! ( "Failed to delete file: {}" , e) ;
131
+ exit ( EXIT_INVALID_INPUT ) ;
132
+ }
133
+ }
85
134
}
86
135
None => {
87
136
error ! ( "Invalid input for file." ) ;
@@ -93,9 +142,21 @@ fn main() {
93
142
debug ! ( "Deleting directory at path: {}" , input) ;
94
143
match parse_directory ( input) {
95
144
Some ( parsed_directory) => {
96
- let dir = delete_dir ( & parsed_directory) . unwrap ( ) ;
97
- let json = serde_json:: to_string ( & dir) . unwrap ( ) ;
98
- println ! ( "{}" , json) ;
145
+ match delete_dir ( & parsed_directory) {
146
+ Ok ( dir) => {
147
+ match serde_json:: to_string ( & dir) {
148
+ Ok ( json) => println ! ( "{}" , json) ,
149
+ Err ( e) => {
150
+ error ! ( "Failed to serialize directory: {}" , e) ;
151
+ exit ( EXIT_INVALID_INPUT ) ;
152
+ }
153
+ }
154
+ }
155
+ Err ( e) => {
156
+ error ! ( "Failed to delete directory: {}" , e) ;
157
+ exit ( EXIT_INVALID_INPUT ) ;
158
+ }
159
+ }
99
160
}
100
161
None => {
101
162
error ! ( "Invalid input for directory." ) ;
@@ -107,9 +168,21 @@ fn main() {
107
168
debug ! ( "Deleting file content at path: {}" , input) ;
108
169
match parse_filecontent ( input) {
109
170
Some ( parsed_filecontent) => {
110
- let filecontent = delete_file_content ( & parsed_filecontent) . unwrap ( ) ;
111
- let json = serde_json:: to_string ( & filecontent) . unwrap ( ) ;
112
- println ! ( "{}" , json) ;
171
+ match delete_file_content ( & parsed_filecontent) {
172
+ Ok ( filecontent) => {
173
+ match serde_json:: to_string ( & filecontent) {
174
+ Ok ( json) => println ! ( "{}" , json) ,
175
+ Err ( e) => {
176
+ error ! ( "Failed to serialize file content: {}" , e) ;
177
+ exit ( EXIT_INVALID_INPUT ) ;
178
+ }
179
+ }
180
+ }
181
+ Err ( e) => {
182
+ error ! ( "Failed to delete file content: {}" , e) ;
183
+ exit ( EXIT_INVALID_INPUT ) ;
184
+ }
185
+ }
113
186
}
114
187
None => {
115
188
error ! ( "Invalid input for file content." ) ;
@@ -126,9 +199,21 @@ fn main() {
126
199
debug ! ( "Setting file at path: {}" , input) ;
127
200
match parse_file ( input) {
128
201
Some ( parsed_file) => {
129
- let file = set_file ( & parsed_file) . unwrap ( ) ;
130
- let json = serde_json:: to_string ( & file) . unwrap ( ) ;
131
- println ! ( "{}" , json) ;
202
+ match set_file ( & parsed_file) {
203
+ Ok ( file) => {
204
+ match serde_json:: to_string ( & file) {
205
+ Ok ( json) => println ! ( "{}" , json) ,
206
+ Err ( e) => {
207
+ error ! ( "Failed to serialize file: {}" , e) ;
208
+ exit ( EXIT_INVALID_INPUT ) ;
209
+ }
210
+ }
211
+ }
212
+ Err ( e) => {
213
+ error ! ( "Failed to set file: {}" , e) ;
214
+ exit ( EXIT_INVALID_INPUT ) ;
215
+ }
216
+ }
132
217
}
133
218
None => {
134
219
error ! ( "Invalid input for file." ) ;
@@ -140,9 +225,21 @@ fn main() {
140
225
debug ! ( "Setting directory at path: {}" , input) ;
141
226
match parse_directory ( input) {
142
227
Some ( parsed_directory) => {
143
- let dir = set_dir ( & parsed_directory) . unwrap ( ) ;
144
- let json = serde_json:: to_string ( & dir) . unwrap ( ) ;
145
- println ! ( "{}" , json) ;
228
+ match set_dir ( & parsed_directory) {
229
+ Ok ( dir) => {
230
+ match serde_json:: to_string ( & dir) {
231
+ Ok ( json) => println ! ( "{}" , json) ,
232
+ Err ( e) => {
233
+ error ! ( "Failed to serialize directory: {}" , e) ;
234
+ exit ( EXIT_INVALID_INPUT ) ;
235
+ }
236
+ }
237
+ }
238
+ Err ( e) => {
239
+ error ! ( "Failed to set directory: {}" , e) ;
240
+ exit ( EXIT_INVALID_INPUT ) ;
241
+ }
242
+ }
146
243
}
147
244
None => {
148
245
error ! ( "Invalid input for directory." ) ;
@@ -154,9 +251,21 @@ fn main() {
154
251
debug ! ( "Setting file content at path: {}" , input) ;
155
252
match parse_filecontent ( input) {
156
253
Some ( parsed_filecontent) => {
157
- let filecontent = set_file_content ( & parsed_filecontent) . unwrap ( ) ;
158
- let json = serde_json:: to_string ( & filecontent) . unwrap ( ) ;
159
- println ! ( "{}" , json) ;
254
+ match set_file_content ( & parsed_filecontent) {
255
+ Ok ( filecontent) => {
256
+ match serde_json:: to_string ( & filecontent) {
257
+ Ok ( json) => println ! ( "{}" , json) ,
258
+ Err ( e) => {
259
+ error ! ( "Failed to serialize file content: {}" , e) ;
260
+ exit ( EXIT_INVALID_INPUT ) ;
261
+ }
262
+ }
263
+ }
264
+ Err ( e) => {
265
+ error ! ( "Failed to set file content: {}" , e) ;
266
+ exit ( EXIT_INVALID_INPUT ) ;
267
+ }
268
+ }
160
269
}
161
270
None => {
162
271
error ! ( "Invalid input for file content." ) ;
@@ -174,9 +283,21 @@ fn main() {
174
283
debug ! ( "Exporting file at path: {}" , input) ;
175
284
match parse_file ( input) {
176
285
Some ( parsed_file) => {
177
- let file = export_file_path ( & parsed_file) . unwrap ( ) ;
178
- let json = serde_json:: to_string ( & file) . unwrap ( ) ;
179
- println ! ( "{}" , json) ;
286
+ match export_file_path ( & parsed_file) {
287
+ Ok ( file) => {
288
+ match serde_json:: to_string ( & file) {
289
+ Ok ( json) => println ! ( "{}" , json) ,
290
+ Err ( e) => {
291
+ error ! ( "Failed to serialize file: {}" , e) ;
292
+ exit ( EXIT_INVALID_INPUT ) ;
293
+ }
294
+ }
295
+ }
296
+ Err ( e) => {
297
+ error ! ( "Failed to export file: {}" , e) ;
298
+ exit ( EXIT_INVALID_INPUT ) ;
299
+ }
300
+ }
180
301
}
181
302
None => {
182
303
error ! ( "Invalid input for file." ) ;
@@ -188,9 +309,21 @@ fn main() {
188
309
debug ! ( "Exporting directory at path: {}" , input) ;
189
310
match parse_directory ( input) {
190
311
Some ( parsed_directory) => {
191
- let dir = export_dir_path ( & parsed_directory) . unwrap ( ) ;
192
- let json = serde_json:: to_string ( & dir) . unwrap ( ) ;
193
- println ! ( "{}" , json) ;
312
+ match export_dir_path ( & parsed_directory) {
313
+ Ok ( dir) => {
314
+ match serde_json:: to_string ( & dir) {
315
+ Ok ( json) => println ! ( "{}" , json) ,
316
+ Err ( e) => {
317
+ error ! ( "Failed to serialize directory: {}" , e) ;
318
+ exit ( EXIT_INVALID_INPUT ) ;
319
+ }
320
+ }
321
+ }
322
+ Err ( e) => {
323
+ error ! ( "Failed to export directory: {}" , e) ;
324
+ exit ( EXIT_INVALID_INPUT ) ;
325
+ }
326
+ }
194
327
}
195
328
None => {
196
329
error ! ( "Invalid input for directory." ) ;
@@ -202,9 +335,21 @@ fn main() {
202
335
debug ! ( "Exporting file content at path: {}" , input) ;
203
336
match parse_filecontent ( input) {
204
337
Some ( parsed_filecontent) => {
205
- let filecontent = get_file_content ( & parsed_filecontent) . unwrap ( ) ;
206
- let json = serde_json:: to_string ( & filecontent) . unwrap ( ) ;
207
- println ! ( "{}" , json) ;
338
+ match get_file_content ( & parsed_filecontent) {
339
+ Ok ( filecontent) => {
340
+ match serde_json:: to_string ( & filecontent) {
341
+ Ok ( json) => println ! ( "{}" , json) ,
342
+ Err ( e) => {
343
+ error ! ( "Failed to serialize file content: {}" , e) ;
344
+ exit ( EXIT_INVALID_INPUT ) ;
345
+ }
346
+ }
347
+ }
348
+ Err ( e) => {
349
+ error ! ( "Failed to export file content: {}" , e) ;
350
+ exit ( EXIT_INVALID_INPUT ) ;
351
+ }
352
+ }
208
353
}
209
354
None => {
210
355
error ! ( "Invalid input for file content." ) ;
@@ -218,18 +363,33 @@ fn main() {
218
363
match schema_type {
219
364
args:: FileSystemObjectType :: File => {
220
365
let schema = schema_for ! ( File ) ;
221
- let json = serde_json:: to_string ( & schema) . unwrap ( ) ;
222
- println ! ( "{}" , json) ;
366
+ match serde_json:: to_string ( & schema) {
367
+ Ok ( json) => println ! ( "{}" , json) ,
368
+ Err ( e) => {
369
+ error ! ( "Failed to serialize file schema: {}" , e) ;
370
+ exit ( EXIT_JSON_SERIALIZATION_FAILED ) ;
371
+ }
372
+ }
223
373
}
224
374
args:: FileSystemObjectType :: Directory => {
225
375
let schema = schema_for ! ( Directory ) ;
226
- let json = serde_json:: to_string ( & schema) . unwrap ( ) ;
227
- println ! ( "{}" , json) ;
376
+ match serde_json:: to_string ( & schema) {
377
+ Ok ( json) => println ! ( "{}" , json) ,
378
+ Err ( e) => {
379
+ error ! ( "Failed to serialize directory schema: {}" , e) ;
380
+ exit ( EXIT_JSON_SERIALIZATION_FAILED ) ;
381
+ }
382
+ }
228
383
}
229
384
args:: FileSystemObjectType :: FileContent => {
230
385
let schema = schema_for ! ( FileContent ) ;
231
- let json = serde_json:: to_string ( & schema) . unwrap ( ) ;
232
- println ! ( "{}" , json) ;
386
+ match serde_json:: to_string ( & schema) {
387
+ Ok ( json) => println ! ( "{}" , json) ,
388
+ Err ( e) => {
389
+ error ! ( "Failed to serialize file content schema: {}" , e) ;
390
+ exit ( EXIT_JSON_SERIALIZATION_FAILED ) ;
391
+ }
392
+ }
233
393
}
234
394
}
235
395
}
0 commit comments