use std::path::PathBuf;
use anyhow::Result;
use clap::Args;
use crate::{
commands::{cli_context::CliContext, get_default_collection},
exports::gfa::export_gfa,
};
#[derive(Debug, Args, Clone)]
pub struct Command {
#[clap(index = 1)]
pub path: String,
#[arg(short, long)]
name: Option<String>,
#[arg(short, long)]
sample: String,
#[arg(long)]
node_max: Option<i64>,
}
pub fn execute(cli_context: &CliContext, cmd: Command) -> Result<()> {
println!("GFA export 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));
export_gfa(
conn,
name,
&PathBuf::from(cmd.path),
cmd.sample.as_str(),
cmd.node_max,
)?;
conn.execute("END TRANSACTION", [])?;
operation_conn.execute("END TRANSACTION", [])?;
Ok(())
}