leo_lang/cli/commands/
run.rs1use super::*;
18
19use snarkvm::cli::Run as SnarkVMRun;
20
21#[derive(Parser, Debug)]
23pub struct LeoRun {
24 #[clap(name = "NAME", help = "The name of the program to run.", default_value = "main")]
25 pub(crate) name: String,
26 #[clap(name = "INPUTS", help = "The inputs to the program.")]
27 pub(crate) inputs: Vec<String>,
28 #[clap(flatten)]
29 pub(crate) compiler_options: BuildOptions,
30 #[clap(flatten)]
31 pub(crate) env_override: EnvOptions,
32}
33
34impl Command for LeoRun {
35 type Input = <LeoBuild as Command>::Output;
36 type Output = ();
37
38 fn log_span(&self) -> Span {
39 tracing::span!(tracing::Level::INFO, "Leo")
40 }
41
42 fn prelude(&self, context: Context) -> Result<Self::Input> {
43 (LeoBuild { options: self.compiler_options.clone(), env_override: self.env_override.clone() }).execute(context)
44 }
45
46 fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
47 handle_run(self, context)
48 }
49}
50
51fn handle_run(mut command: LeoRun, context: Context) -> Result<<LeoRun as Command>::Output> {
53 let mut arguments = vec![SNARKVM_COMMAND.to_string(), command.name, "--".to_string()];
57 arguments.append(&mut command.inputs);
58
59 let path = context.dir()?;
61 let build_directory = path.join(leo_package::BUILD_DIRECTORY);
62
63 std::env::set_current_dir(&build_directory)
65 .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?;
66
67 let _ = std::panic::take_hook();
69
70 println!();
72 let command = SnarkVMRun::try_parse_from(&arguments).map_err(CliError::failed_to_parse_run)?;
73 let res = command.parse().map_err(CliError::failed_to_execute_run)?;
74
75 tracing::info!("{}", res);
77
78 Ok(())
79}