@@ -109,15 +109,16 @@ enum SecretCommand {
109
109
key : String ,
110
110
value : String ,
111
111
112
+ #[ arg( help = "The ID of the project this secret will be added to" ) ]
113
+ project_id : Uuid ,
114
+
112
115
#[ arg( long, help = "An optional note to add to the secret" ) ]
113
116
note : Option < String > ,
114
-
115
- #[ arg( long, help = "The ID of the project this secret will be added to" ) ]
116
- project_id : Option < Uuid > ,
117
117
} ,
118
118
Delete {
119
119
secret_ids : Vec < Uuid > ,
120
120
} ,
121
+ #[ clap( group = ArgGroup :: new( "edit_field" ) . required( true ) . multiple( true ) ) ]
121
122
Edit {
122
123
secret_id : Uuid ,
123
124
#[ arg( long, group = "edit_field" ) ]
@@ -126,6 +127,8 @@ enum SecretCommand {
126
127
value : Option < String > ,
127
128
#[ arg( long, group = "edit_field" ) ]
128
129
note : Option < String > ,
130
+ #[ arg( long, group = "edit_field" ) ]
131
+ project_id : Option < Uuid > ,
129
132
} ,
130
133
Get {
131
134
secret_id : Uuid ,
@@ -179,7 +182,7 @@ enum CreateCommand {
179
182
note : Option < String > ,
180
183
181
184
#[ arg( long, help = "The ID of the project this secret will be added to" ) ]
182
- project_id : Option < Uuid > ,
185
+ project_id : Uuid ,
183
186
} ,
184
187
}
185
188
@@ -200,6 +203,8 @@ enum EditCommand {
200
203
value : Option < String > ,
201
204
#[ arg( long, group = "edit_field" ) ]
202
205
note : Option < String > ,
206
+ #[ arg( long, group = "edit_field" ) ]
207
+ project_id : Option < Uuid > ,
203
208
} ,
204
209
}
205
210
@@ -383,17 +388,34 @@ async fn process_commands() -> Result<()> {
383
388
| Commands :: Delete {
384
389
cmd : DeleteCommand :: Project { project_ids } ,
385
390
} => {
386
- let project_count = project_ids. len ( ) ;
391
+ let count = project_ids. len ( ) ;
387
392
388
- client
393
+ let result = client
389
394
. projects ( )
390
395
. delete ( ProjectsDeleteRequest { ids : project_ids } )
391
396
. await ?;
392
397
393
- if project_count > 1 {
394
- println ! ( "Projects deleted successfully." ) ;
395
- } else {
396
- println ! ( "Project deleted successfully." ) ;
398
+ let projects_failed: Vec < ( Uuid , String ) > = result
399
+ . data
400
+ . into_iter ( )
401
+ . filter_map ( |r| r. error . map ( |e| ( r. id , e) ) )
402
+ . collect ( ) ;
403
+ let deleted_projects = count - projects_failed. len ( ) ;
404
+
405
+ if deleted_projects > 1 {
406
+ println ! ( "{} projects deleted successfully." , deleted_projects) ;
407
+ } else if deleted_projects == 1 {
408
+ println ! ( "{} project deleted successfully." , deleted_projects) ;
409
+ }
410
+
411
+ if projects_failed. len ( ) > 1 {
412
+ println ! ( "{} projects had errors:" , projects_failed. len( ) ) ;
413
+ } else if projects_failed. len ( ) == 1 {
414
+ println ! ( "{} project had an error:" , projects_failed. len( ) ) ;
415
+ }
416
+
417
+ for project in projects_failed {
418
+ println ! ( "{}: {}" , project. 0 , project. 1 ) ;
397
419
}
398
420
}
399
421
@@ -466,7 +488,7 @@ async fn process_commands() -> Result<()> {
466
488
key,
467
489
value,
468
490
note : note. unwrap_or_default ( ) ,
469
- project_ids : project_id . map ( |p| vec ! [ p ] ) ,
491
+ project_ids : Some ( vec ! [ project_id ] ) ,
470
492
} )
471
493
. await ?;
472
494
serialize_response ( secret, cli. output , color) ;
@@ -479,6 +501,7 @@ async fn process_commands() -> Result<()> {
479
501
key,
480
502
value,
481
503
note,
504
+ project_id,
482
505
} ,
483
506
}
484
507
| Commands :: Edit {
@@ -488,6 +511,7 @@ async fn process_commands() -> Result<()> {
488
511
key,
489
512
value,
490
513
note,
514
+ project_id,
491
515
} ,
492
516
} => {
493
517
let old_secret = client
@@ -505,6 +529,13 @@ async fn process_commands() -> Result<()> {
505
529
key : key. unwrap_or ( old_secret. key ) ,
506
530
value : value. unwrap_or ( old_secret. value ) ,
507
531
note : note. unwrap_or ( old_secret. note ) ,
532
+ project_ids : match project_id {
533
+ Some ( id) => Some ( vec ! [ id] ) ,
534
+ None => match old_secret. project_id {
535
+ Some ( id) => Some ( vec ! [ id] ) ,
536
+ None => bail ! ( "Editing a secret requires a project_id." ) ,
537
+ } ,
538
+ } ,
508
539
} )
509
540
. await ?;
510
541
serialize_response ( secret, cli. output , color) ;
@@ -516,12 +547,35 @@ async fn process_commands() -> Result<()> {
516
547
| Commands :: Delete {
517
548
cmd : DeleteCommand :: Secret { secret_ids } ,
518
549
} => {
519
- client
550
+ let count = secret_ids. len ( ) ;
551
+
552
+ let result = client
520
553
. secrets ( )
521
554
. delete ( SecretsDeleteRequest { ids : secret_ids } )
522
555
. await ?;
523
556
524
- println ! ( "Secret deleted correctly" ) ;
557
+ let secrets_failed: Vec < ( Uuid , String ) > = result
558
+ . data
559
+ . into_iter ( )
560
+ . filter_map ( |r| r. error . map ( |e| ( r. id , e) ) )
561
+ . collect ( ) ;
562
+ let deleted_secrets = count - secrets_failed. len ( ) ;
563
+
564
+ if deleted_secrets > 1 {
565
+ println ! ( "{} secrets deleted successfully." , deleted_secrets) ;
566
+ } else if deleted_secrets == 1 {
567
+ println ! ( "{} secret deleted successfully." , deleted_secrets) ;
568
+ }
569
+
570
+ if secrets_failed. len ( ) > 1 {
571
+ println ! ( "{} secrets had errors:" , secrets_failed. len( ) ) ;
572
+ } else if secrets_failed. len ( ) == 1 {
573
+ println ! ( "{} secret had an error:" , secrets_failed. len( ) ) ;
574
+ }
575
+
576
+ for secret in secrets_failed {
577
+ println ! ( "{}: {}" , secret. 0 , secret. 1 ) ;
578
+ }
525
579
}
526
580
527
581
Commands :: Config { .. } => {
0 commit comments