Skip to content

Commit c0657f6

Browse files
committed
Progress with todos, review me
1 parent fcf7ec5 commit c0657f6

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct Args {
4646
#[arg(long = "replication-disabled", default_value = "false")]
4747
pub replication_disabled: bool,
4848

49+
// TODO: Add cluster-related retries/attempts flags from Driver Options?
50+
4951
/// Username for authentication
5052
#[arg(long, value_name = USERNAME_VALUE_NAME)]
5153
pub username: Option<String>,

src/main.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,26 @@ fn execute_commands(
332332
fn entry_repl(driver: Arc<TypeDBDriver>, runtime: BackgroundRuntime) -> Repl<ConsoleContext> {
333333
let server_commands = Subcommand::new("server")
334334
.add(CommandLeaf::new("version", "Retrieve server version.", server_version));
335-
335+
336+
let replica_commands = Subcommand::new("replica")
337+
.add(CommandLeaf::new("list", "List replicas.", replica_list))
338+
.add(CommandLeaf::new("primary", "Get current primary replica.", replica_primary))
339+
.add(CommandLeaf::new_with_inputs(
340+
"register",
341+
"Register new replica. Requires a clustering address, not a connection address.",
342+
vec![
343+
CommandInput::new("replica id", get_word, None, None),
344+
CommandInput::new("clustering address", get_word, None, None),
345+
],
346+
replica_register,
347+
))
348+
.add(CommandLeaf::new_with_input(
349+
"deregister",
350+
"Deregister existing replica.",
351+
CommandInput::new("replica id", get_word, None, None),
352+
replica_deregister,
353+
));
354+
336355
let database_commands = Subcommand::new("database")
337356
.add(CommandLeaf::new("list", "List databases on the server.", database_list))
338357
.add(CommandLeaf::new_with_input(
@@ -406,25 +425,6 @@ fn entry_repl(driver: Arc<TypeDBDriver>, runtime: BackgroundRuntime) -> Repl<Con
406425
user_update_password,
407426
));
408427

409-
let replica_commands = Subcommand::new("replica")
410-
.add(CommandLeaf::new("list", "List replicas.", replica_list))
411-
.add(CommandLeaf::new("primary", "Get current primary replica.", replica_primary))
412-
.add(CommandLeaf::new_with_inputs(
413-
"register",
414-
"Register new replica.",
415-
vec![
416-
CommandInput::new("replica id", get_word, None, None),
417-
CommandInput::new("address", get_word, None, None),
418-
],
419-
replica_register,
420-
))
421-
.add(CommandLeaf::new_with_input(
422-
"deregister",
423-
"Deregister existing replica.",
424-
CommandInput::new("replica id", get_word, None, None),
425-
replica_deregister,
426-
));
427-
428428
let transaction_commands = Subcommand::new("transaction")
429429
.add(CommandLeaf::new_with_input(
430430
"read",
@@ -514,7 +514,6 @@ fn parse_addresses(args: &Args) -> AddressInfo {
514514
AddressInfo {only_https: is_https_address(address), addresses: Addresses::try_from_address_str(address).unwrap() }
515515
} else if let Some(addresses) = &args.addresses {
516516
let split = addresses.split(',').map(str::to_string).collect::<Vec<_>>();
517-
println!("Split: {split:?}");
518517
let only_https = split.iter().all(|address| is_https_address(address));
519518
AddressInfo {only_https, addresses: Addresses::try_from_addresses_str(split).unwrap() }
520519
} else if let Some(translation) = &args.address_translation {
@@ -527,7 +526,7 @@ fn parse_addresses(args: &Args) -> AddressInfo {
527526
only_https = only_https && is_https_address(public_address);
528527
map.insert(public_address.to_string(), private_address.to_string());
529528
}
530-
println!("Translation map:: {map:?}");
529+
println!("Translation map:: {map:?}"); // TODO: Remove
531530
AddressInfo {only_https, addresses: Addresses::try_from_translation_str(map).unwrap() }
532531
} else {
533532
panic!("At least one of --address, --addresses, or --address-translation must be provided.");

src/operations.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,17 @@ pub(crate) fn user_update_password(context: &mut ConsoleContext, input: &[String
198198

199199
pub(crate) fn replica_list(context: &mut ConsoleContext, _input: &[String]) -> CommandResult {
200200
let driver = context.driver.clone();
201-
let replicas = driver.replicas();
202-
if replicas.is_empty() {
203-
println!("No replicas are present.");
204-
} else {
205-
for replica in replicas {
206-
println!("{}", replica.address());
201+
context.background_runtime.run(async move {
202+
let replicas = driver.replicas().await.map_err(|err| Box::new(err) as Box<dyn Error + Send>)?;
203+
if replicas.is_empty() {
204+
println!("No replicas are present.");
205+
} else {
206+
for replica in replicas {
207+
println!("{}", replica.address());
208+
}
207209
}
208-
}
209-
Ok(())
210+
Ok(())
211+
})
210212
}
211213

212214
pub(crate) fn replica_primary(context: &mut ConsoleContext, _input: &[String]) -> CommandResult {

0 commit comments

Comments
 (0)