11//! Implementation of additional subscription commands
22
3+ use super :: async_utils:: { AsyncOperationArgs , handle_async_response} ;
34use super :: utils:: * ;
45use crate :: cli:: OutputFormat ;
56use crate :: connection:: ConnectionManager ;
@@ -41,6 +42,7 @@ pub async fn create_subscription(
4142 conn_mgr : & ConnectionManager ,
4243 profile_name : Option < & str > ,
4344 data : & str ,
45+ async_ops : & AsyncOperationArgs ,
4446 output_format : OutputFormat ,
4547 query : Option < & str > ,
4648) -> CliResult < ( ) > {
@@ -52,26 +54,16 @@ pub async fn create_subscription(
5254 . await
5355 . context ( "Failed to create subscription" ) ?;
5456
55- let result = if let Some ( q) = query {
56- apply_jmespath ( & response, q) ?
57- } else {
58- response
59- } ;
60-
61- match output_format {
62- OutputFormat :: Table => {
63- println ! ( "Subscription created successfully" ) ;
64- if let Some ( task_id) = result. get ( "taskId" ) {
65- println ! ( "Task ID: {}" , task_id) ;
66- }
67- if let Some ( sub_id) = result. get ( "resourceId" ) {
68- println ! ( "Subscription ID: {}" , sub_id) ;
69- }
70- }
71- _ => print_json_or_yaml ( result, output_format) ?,
72- }
73-
74- Ok ( ( ) )
57+ handle_async_response (
58+ conn_mgr,
59+ profile_name,
60+ response,
61+ async_ops,
62+ output_format,
63+ query,
64+ "Subscription created successfully" ,
65+ )
66+ . await
7567}
7668
7769/// Update subscription configuration
@@ -80,6 +72,7 @@ pub async fn update_subscription(
8072 profile_name : Option < & str > ,
8173 id : u32 ,
8274 data : & str ,
75+ async_ops : & AsyncOperationArgs ,
8376 output_format : OutputFormat ,
8477 query : Option < & str > ,
8578) -> CliResult < ( ) > {
@@ -91,23 +84,16 @@ pub async fn update_subscription(
9184 . await
9285 . context ( "Failed to update subscription" ) ?;
9386
94- let result = if let Some ( q) = query {
95- apply_jmespath ( & response, q) ?
96- } else {
97- response
98- } ;
99-
100- match output_format {
101- OutputFormat :: Table => {
102- println ! ( "Subscription updated successfully" ) ;
103- if let Some ( task_id) = result. get ( "taskId" ) {
104- println ! ( "Task ID: {}" , task_id) ;
105- }
106- }
107- _ => print_json_or_yaml ( result, output_format) ?,
108- }
109-
110- Ok ( ( ) )
87+ handle_async_response (
88+ conn_mgr,
89+ profile_name,
90+ response,
91+ async_ops,
92+ output_format,
93+ query,
94+ "Subscription updated successfully" ,
95+ )
96+ . await
11197}
11298
11399/// Delete a subscription
@@ -116,6 +102,7 @@ pub async fn delete_subscription(
116102 profile_name : Option < & str > ,
117103 id : u32 ,
118104 force : bool ,
105+ async_ops : & AsyncOperationArgs ,
119106 output_format : OutputFormat ,
120107 query : Option < & str > ,
121108) -> CliResult < ( ) > {
@@ -143,23 +130,16 @@ pub async fn delete_subscription(
143130 . await
144131 . context ( "Failed to delete subscription" ) ?;
145132
146- let result = if let Some ( q) = query {
147- apply_jmespath ( & response, q) ?
148- } else {
149- response
150- } ;
151-
152- match output_format {
153- OutputFormat :: Table => {
154- println ! ( "Subscription deletion initiated" ) ;
155- if let Some ( task_id) = result. get ( "taskId" ) {
156- println ! ( "Task ID: {}" , task_id) ;
157- }
158- }
159- _ => print_json_or_yaml ( result, output_format) ?,
160- }
161-
162- Ok ( ( ) )
133+ handle_async_response (
134+ conn_mgr,
135+ profile_name,
136+ response,
137+ async_ops,
138+ output_format,
139+ query,
140+ "Subscription deletion initiated" ,
141+ )
142+ . await
163143}
164144
165145/// Redis version info for table display
0 commit comments