Skip to content

Commit 5f05783

Browse files
Merge pull request #198 from joshrotenberg/feat/fixed-commands-wait-flag
feat(cloud): add --wait flag support for fixed database and subscription commands
2 parents 0065c65 + 2b3260d commit 5f05783

File tree

3 files changed

+126
-105
lines changed

3 files changed

+126
-105
lines changed

crates/redisctl/src/cli.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,19 @@ pub enum CloudFixedDatabaseCommands {
614614
subscription_id: i32,
615615
/// JSON file with database configuration (use @filename or - for stdin)
616616
file: String,
617+
/// Async operation options
618+
#[command(flatten)]
619+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
617620
},
618621
/// Update fixed database configuration
619622
Update {
620623
/// Database ID (format: subscription_id:database_id)
621624
id: String,
622625
/// JSON file with update configuration (use @filename or - for stdin)
623626
file: String,
627+
/// Async operation options
628+
#[command(flatten)]
629+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
624630
},
625631
/// Delete a fixed database
626632
Delete {
@@ -629,6 +635,9 @@ pub enum CloudFixedDatabaseCommands {
629635
/// Skip confirmation prompt
630636
#[arg(short, long)]
631637
yes: bool,
638+
/// Async operation options
639+
#[command(flatten)]
640+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
632641
},
633642
/// Get backup status for fixed database
634643
#[command(name = "backup-status")]
@@ -640,6 +649,9 @@ pub enum CloudFixedDatabaseCommands {
640649
Backup {
641650
/// Database ID (format: subscription_id:database_id)
642651
id: String,
652+
/// Async operation options
653+
#[command(flatten)]
654+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
643655
},
644656
/// Get import status
645657
#[command(name = "import-status")]
@@ -653,6 +665,9 @@ pub enum CloudFixedDatabaseCommands {
653665
id: String,
654666
/// JSON file with import configuration (use @filename or - for stdin)
655667
file: String,
668+
/// Async operation options
669+
#[command(flatten)]
670+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
656671
},
657672
/// View slow query log
658673
#[command(name = "slow-log")]
@@ -749,13 +764,19 @@ pub enum CloudFixedSubscriptionCommands {
749764
Create {
750765
/// JSON file with subscription configuration (use @filename or - for stdin)
751766
file: String,
767+
/// Async operation options
768+
#[command(flatten)]
769+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
752770
},
753771
/// Update fixed subscription
754772
Update {
755773
/// Subscription ID
756774
id: i32,
757775
/// JSON file with update configuration (use @filename or - for stdin)
758776
file: String,
777+
/// Async operation options
778+
#[command(flatten)]
779+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
759780
},
760781
/// Delete a fixed subscription
761782
Delete {
@@ -764,6 +785,9 @@ pub enum CloudFixedSubscriptionCommands {
764785
/// Skip confirmation prompt
765786
#[arg(short, long)]
766787
yes: bool,
788+
/// Async operation options
789+
#[command(flatten)]
790+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
767791
},
768792
/// Get available Redis versions for fixed subscription
769793
#[command(name = "redis-versions")]

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

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![allow(dead_code)]
44

55
use crate::cli::{CloudFixedDatabaseCommands, OutputFormat};
6+
use crate::commands::cloud::async_utils::handle_async_response;
67
use crate::commands::cloud::utils::{
78
confirm_action, handle_output, print_formatted_output, read_file_input,
89
};
@@ -83,6 +84,7 @@ pub async fn handle_fixed_database_command(
8384
CloudFixedDatabaseCommands::Create {
8485
subscription_id,
8586
file,
87+
async_ops,
8688
} => {
8789
let json_string = read_file_input(file)?;
8890
let request: FixedDatabaseCreateRequest =
@@ -93,23 +95,26 @@ pub async fn handle_fixed_database_command(
9395
.await
9496
.context("Failed to create fixed database")?;
9597

96-
// Check if response contains a task ID
9798
let json_result =
9899
serde_json::to_value(&result).context("Failed to serialize response")?;
99-
if let Some(task_id) = json_result.get("taskId").and_then(|v| v.as_str()) {
100-
eprintln!("Fixed database creation initiated. Task ID: {}", task_id);
101-
eprintln!(
102-
"Use 'redisctl cloud task wait {}' to monitor progress",
103-
task_id
104-
);
105-
}
106100

107-
let data = handle_output(json_result, output_format, query)?;
108-
print_formatted_output(data, output_format)?;
109-
Ok(())
101+
handle_async_response(
102+
conn_mgr,
103+
profile_name,
104+
json_result,
105+
async_ops,
106+
output_format,
107+
query,
108+
"Fixed database created successfully",
109+
)
110+
.await
110111
}
111112

112-
CloudFixedDatabaseCommands::Update { id, file } => {
113+
CloudFixedDatabaseCommands::Update {
114+
id,
115+
file,
116+
async_ops,
117+
} => {
113118
let (subscription_id, database_id) = parse_fixed_database_id(id)?;
114119
let json_string = read_file_input(file)?;
115120
let request: FixedDatabaseUpdateRequest =
@@ -120,23 +125,22 @@ pub async fn handle_fixed_database_command(
120125
.await
121126
.context("Failed to update fixed database")?;
122127

123-
// Check if response contains a task ID
124128
let json_result =
125129
serde_json::to_value(&result).context("Failed to serialize response")?;
126-
if let Some(task_id) = json_result.get("taskId").and_then(|v| v.as_str()) {
127-
eprintln!("Fixed database update initiated. Task ID: {}", task_id);
128-
eprintln!(
129-
"Use 'redisctl cloud task wait {}' to monitor progress",
130-
task_id
131-
);
132-
}
133130

134-
let data = handle_output(json_result, output_format, query)?;
135-
print_formatted_output(data, output_format)?;
136-
Ok(())
131+
handle_async_response(
132+
conn_mgr,
133+
profile_name,
134+
json_result,
135+
async_ops,
136+
output_format,
137+
query,
138+
"Fixed database updated successfully",
139+
)
140+
.await
137141
}
138142

139-
CloudFixedDatabaseCommands::Delete { id, yes } => {
143+
CloudFixedDatabaseCommands::Delete { id, yes, async_ops } => {
140144
let (subscription_id, database_id) = parse_fixed_database_id(id)?;
141145

142146
if !yes {
@@ -152,22 +156,19 @@ pub async fn handle_fixed_database_command(
152156
.await
153157
.context("Failed to delete fixed database")?;
154158

155-
// Check if response contains a task ID
156159
let json_result =
157160
serde_json::to_value(&result).context("Failed to serialize response")?;
158-
if let Some(task_id) = json_result.get("taskId").and_then(|v| v.as_str()) {
159-
eprintln!("Fixed database deletion initiated. Task ID: {}", task_id);
160-
eprintln!(
161-
"Use 'redisctl cloud task wait {}' to monitor progress",
162-
task_id
163-
);
164-
} else {
165-
eprintln!("Fixed database deleted successfully");
166-
}
167161

168-
let data = handle_output(json_result, output_format, query)?;
169-
print_formatted_output(data, output_format)?;
170-
Ok(())
162+
handle_async_response(
163+
conn_mgr,
164+
profile_name,
165+
json_result,
166+
async_ops,
167+
output_format,
168+
query,
169+
"Fixed database deleted successfully",
170+
)
171+
.await
171172
}
172173

173174
CloudFixedDatabaseCommands::BackupStatus { id } => {
@@ -184,7 +185,7 @@ pub async fn handle_fixed_database_command(
184185
Ok(())
185186
}
186187

187-
CloudFixedDatabaseCommands::Backup { id } => {
188+
CloudFixedDatabaseCommands::Backup { id, async_ops } => {
188189
let (subscription_id, database_id) = parse_fixed_database_id(id)?;
189190

190191
// Create a minimal backup request - most fields are optional
@@ -201,20 +202,19 @@ pub async fn handle_fixed_database_command(
201202
.await
202203
.context("Failed to initiate backup")?;
203204

204-
// Check if response contains a task ID
205205
let json_result =
206206
serde_json::to_value(&result).context("Failed to serialize response")?;
207-
if let Some(task_id) = json_result.get("taskId").and_then(|v| v.as_str()) {
208-
eprintln!("Backup initiated. Task ID: {}", task_id);
209-
eprintln!(
210-
"Use 'redisctl cloud task wait {}' to monitor progress",
211-
task_id
212-
);
213-
}
214207

215-
let data = handle_output(json_result, output_format, query)?;
216-
print_formatted_output(data, output_format)?;
217-
Ok(())
208+
handle_async_response(
209+
conn_mgr,
210+
profile_name,
211+
json_result,
212+
async_ops,
213+
output_format,
214+
query,
215+
"Backup initiated successfully",
216+
)
217+
.await
218218
}
219219

220220
CloudFixedDatabaseCommands::ImportStatus { id } => {
@@ -231,7 +231,11 @@ pub async fn handle_fixed_database_command(
231231
Ok(())
232232
}
233233

234-
CloudFixedDatabaseCommands::Import { id, file } => {
234+
CloudFixedDatabaseCommands::Import {
235+
id,
236+
file,
237+
async_ops,
238+
} => {
235239
let (subscription_id, database_id) = parse_fixed_database_id(id)?;
236240
let json_string = read_file_input(file)?;
237241
let request: FixedDatabaseImportRequest =
@@ -242,20 +246,19 @@ pub async fn handle_fixed_database_command(
242246
.await
243247
.context("Failed to initiate import")?;
244248

245-
// Check if response contains a task ID
246249
let json_result =
247250
serde_json::to_value(&result).context("Failed to serialize response")?;
248-
if let Some(task_id) = json_result.get("taskId").and_then(|v| v.as_str()) {
249-
eprintln!("Import initiated. Task ID: {}", task_id);
250-
eprintln!(
251-
"Use 'redisctl cloud task wait {}' to monitor progress",
252-
task_id
253-
);
254-
}
255251

256-
let data = handle_output(json_result, output_format, query)?;
257-
print_formatted_output(data, output_format)?;
258-
Ok(())
252+
handle_async_response(
253+
conn_mgr,
254+
profile_name,
255+
json_result,
256+
async_ops,
257+
output_format,
258+
query,
259+
"Import initiated successfully",
260+
)
261+
.await
259262
}
260263

261264
CloudFixedDatabaseCommands::SlowLog {

0 commit comments

Comments
 (0)