use std::path::PathBuf;
use std::process;
use clap::Args;
use joy_rs::Warrior;
use trident::runtime::Runner;
use super::{check_target, load_bundle, make_input};
#[derive(Args)]
pub struct RunArgs {
pub input: PathBuf,
#[arg(long)]
pub target: Option<String>,
#[arg(long, default_value = "debug")]
pub profile: String,
#[arg(long, value_delimiter = ',')]
pub input_values: Option<Vec<u64>>,
#[arg(long, value_delimiter = ',')]
pub secret: Option<Vec<u64>>,
#[arg(long, default_value_t = joy_rs::DEFAULT_BUDGET)]
pub budget: u64,
#[arg(long)]
pub state: Option<String>,
}
pub fn cmd_run(args: RunArgs) {
if let Err(e) = check_target(args.target.as_deref().unwrap_or("nox")) {
eprintln!("error: {}", e);
process::exit(1);
}
let bundle = match load_bundle(&args.input, &args.profile, args.target.as_deref()) {
Ok(b) => b,
Err(e) => {
eprintln!("error: {}", e);
process::exit(1);
}
};
let pi = make_input(&args.input_values, &args.secret);
let warrior = Warrior::with_budget(args.budget);
let result = if let Some(path) = &args.state {
joy_rs::state_execution::load_certificate(std::path::Path::new(path)).and_then(
|certificate| warrior.run_state_certificate(&bundle, &pi, &certificate, args.budget),
)
} else {
warrior.run(&bundle, &pi)
};
match result {
Ok(result) => {
for val in &result.output {
println!("{}", val);
}
eprintln!("Executed in {} reductions", result.cycle_count);
}
Err(e) => {
eprintln!("error: {}", e);
process::exit(1);
}
}
}