Skip to content

Commit 0065c65

Browse files
Merge pull request #197 from joshrotenberg/feat/subscription-wait-flag
feat(cloud): add --wait flag to subscription commands
2 parents a356198 + fe0f587 commit 0065c65

File tree

3 files changed

+57
-57
lines changed

3 files changed

+57
-57
lines changed

crates/redisctl/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,9 @@ pub enum CloudSubscriptionCommands {
953953
/// Subscription configuration as JSON string or @file.json
954954
#[arg(long)]
955955
data: String,
956+
/// Async operation options
957+
#[command(flatten)]
958+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
956959
},
957960

958961
/// Update subscription configuration
@@ -962,6 +965,9 @@ pub enum CloudSubscriptionCommands {
962965
/// Update configuration as JSON string or @file.json
963966
#[arg(long)]
964967
data: String,
968+
/// Async operation options
969+
#[command(flatten)]
970+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
965971
},
966972

967973
/// Delete a subscription
@@ -971,6 +977,9 @@ pub enum CloudSubscriptionCommands {
971977
/// Skip confirmation prompt
972978
#[arg(long)]
973979
force: bool,
980+
/// Async operation options
981+
#[command(flatten)]
982+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
974983
},
975984

976985
/// Get available Redis versions

crates/redisctl/src/commands/cloud/subscription.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,44 @@ pub async fn handle_subscription_command(
4949
CloudSubscriptionCommands::Get { id } => {
5050
get_subscription(conn_mgr, profile_name, *id, output_format, query).await
5151
}
52-
CloudSubscriptionCommands::Create { data } => {
52+
CloudSubscriptionCommands::Create { data, async_ops } => {
5353
subscription_impl::create_subscription(
5454
conn_mgr,
5555
profile_name,
5656
data,
57+
async_ops,
5758
output_format,
5859
query,
5960
)
6061
.await
6162
}
62-
CloudSubscriptionCommands::Update { id, data } => {
63+
CloudSubscriptionCommands::Update {
64+
id,
65+
data,
66+
async_ops,
67+
} => {
6368
subscription_impl::update_subscription(
6469
conn_mgr,
6570
profile_name,
6671
*id,
6772
data,
73+
async_ops,
6874
output_format,
6975
query,
7076
)
7177
.await
7278
}
73-
CloudSubscriptionCommands::Delete { id, force } => {
79+
CloudSubscriptionCommands::Delete {
80+
id,
81+
force,
82+
async_ops,
83+
} => {
7484
subscription_impl::delete_subscription(
7585
conn_mgr,
7686
profile_name,
7787
*id,
7888
*force,
89+
async_ops,
7990
output_format,
8091
query,
8192
)

crates/redisctl/src/commands/cloud/subscription_impl.rs

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Implementation of additional subscription commands
22
3+
use super::async_utils::{AsyncOperationArgs, handle_async_response};
34
use super::utils::*;
45
use crate::cli::OutputFormat;
56
use 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

Comments
 (0)