use std::path::PathBuf;
use clap::Parser;
use crate::CommonOpts;
use crate::cli_wrapper::Hermit;
use crate::common::TemporaryEnvironment;
use crate::common::TemporaryEnvironmentBuilder;
use crate::use_case::UseCase;
#[derive(Parser, Debug)]
pub struct RunOpts {
#[clap(long)]
keep_temp_dir: bool,
#[clap(long)]
isolate_workdir: bool,
#[clap(long)]
concurrent: bool,
#[clap(long, default_value = "2")]
run_count: i32,
#[clap(long, short = 'a')]
hermit_arg: Vec<String>,
#[clap(value_name = "PROGRAM")]
guest_program: PathBuf,
#[clap(value_name = "ARGS")]
args: Vec<String>,
}
impl UseCase for RunOpts {
fn build_temp_env(
&self,
common_args: &CommonOpts,
) -> crate::common::TemporaryEnvironmentBuilder {
TemporaryEnvironmentBuilder::new()
.persist_temp_dir(self.keep_temp_dir)
.temp_dir_path(common_args.temp_dir_path.as_ref())
.run_count(self.run_count)
}
fn build_first_hermit_args(
&self,
temp_env: &TemporaryEnvironment,
current_run: &crate::common::RunEnvironment,
) -> Vec<String> {
Hermit::new()
.log_level(tracing::Level::DEBUG)
.log_file(current_run.log_file_path.clone())
.run(self.guest_program.clone(), self.args.clone())
.hermit_args(self.hermit_arg.clone())
.workdir_isolate(current_run.workdir.clone(), self.isolate_workdir)
.bind(temp_env.path().to_owned())
.into_args()
}
fn build_next_hermit_args(
&self,
_run_no: usize,
temp_env: &TemporaryEnvironment,
_prev_run: &crate::common::RunEnvironment,
current_run: &crate::common::RunEnvironment,
) -> Vec<String> {
self.build_first_hermit_args(temp_env, current_run)
}
}