database_replicator/commands/
target.rs1use anyhow::{Context, Result};
2use clap::{Args, Subcommand};
3
4use crate::state;
5
6#[derive(Args)]
7pub struct TargetArgs {
8 #[command(subcommand)]
9 command: TargetCommands,
10}
11
12#[derive(Subcommand)]
13enum TargetCommands {
14 Set {
16 url: String,
18 },
19 Unset,
21 Get,
23}
24
25pub async fn command(args: TargetArgs) -> Result<()> {
26 match args.command {
27 TargetCommands::Set { url } => {
28 let mut state = state::load().context("Failed to load state")?;
29 state.target_url = Some(url.clone());
30 state::save(&state).context("Failed to save state")?;
31 println!("Target database URL set to: {}", url);
32 }
33 TargetCommands::Unset => {
34 let mut state = state::load().context("Failed to load state")?;
35 state.target_url = None;
36 state::save(&state).context("Failed to save state")?;
37 println!("Target database URL unset.");
38 }
39 TargetCommands::Get => {
40 let state = state::load().context("Failed to load state")?;
41 match state.target_url {
42 Some(url) => println!("Current target database URL: {}", url),
43 None => println!("Target database URL is not set."),
44 }
45 }
46 }
47 Ok(())
48}