use anyhow::Result;
use clap::Args;
use crate::{
commands::{cli_context::CliContext, get_default_collection},
updates::sequence::update_with_sequence,
};
#[derive(Debug, Args)]
pub struct Command {
#[clap(index = 1)]
pub sequence: String,
#[arg(short, long)]
name: Option<String>,
#[arg(short, long)]
sample: Option<String>,
#[arg(long)]
new_sample: String,
#[arg(long)]
region_name: String,
#[arg(long)]
start: i64,
#[arg(short, long)]
end: i64,
#[arg(long, action)]
no_reference_path_update: bool,
}
pub fn execute(cli_context: &CliContext, cmd: Command) -> Result<()> {
println!("Update with sequence called");
let context = cli_context.context;
let operation_conn = context.operations().conn();
let conn = context.graph().conn();
conn.execute("BEGIN TRANSACTION", [])?;
operation_conn.execute("BEGIN TRANSACTION", [])?;
let name = &cmd
.name
.clone()
.unwrap_or_else(|| get_default_collection(operation_conn));
if let Err(err) = update_with_sequence(
context,
name,
cmd.sample.clone().as_deref(),
&cmd.new_sample,
&cmd.region_name,
cmd.start,
cmd.end,
&cmd.sequence,
cmd.no_reference_path_update,
) {
conn.execute("ROLLBACK TRANSACTION;", [])?;
operation_conn.execute("ROLLBACK TRANSACTION;", [])?;
return Err(err.into());
}
conn.execute("END TRANSACTION;", [])?;
operation_conn.execute("END TRANSACTION;", [])?;
Ok(())
}