use clap;
use bark::Wallet;
use bark::persist::models::RoundStateId;
#[derive(clap::Subcommand)]
pub enum RoundCommand {
#[command()]
Cancel {
#[clap(long)]
round: Option<u32>,
#[clap(long)]
all: bool,
},
#[command()]
Progress {
#[clap(long = "continue")]
cont: bool,
},
}
pub async fn execute_round_command(
cmd: RoundCommand,
wallet: &mut Wallet,
) -> anyhow::Result<()> {
match cmd {
RoundCommand::Cancel { round, all } => {
if all {
wallet.cancel_all_pending_rounds().await?;
} else if let Some(id) = round {
wallet.cancel_pending_round(RoundStateId(id)).await?;
} else {
bail!("must provide either a round id or --all");
}
},
RoundCommand::Progress { cont } => {
if cont {
wallet.participate_ongoing_rounds().await?;
} else {
wallet.progress_pending_rounds(None).await?;
}
},
}
Ok(())
}