From 700e31f11322070d0c4d785903852900695a4dac Mon Sep 17 00:00:00 2001 From: Collin Chin <16715212+collinc97@users.noreply.github.com> Date: Tue, 15 Aug 2023 13:59:50 -0700 Subject: [PATCH] fix leo execute command line argument parsing (#2530) * fix leo execute command line argument parsing * add leo-examples integration test to ci and include leo execute commands * give leo-example.sh execute permission --- .circleci/config.yml | 16 ++++++++++++++++ .circleci/leo-example.sh | 11 ++++++++++- leo/cli/commands/execute.rs | 31 +++++++++++++++++++------------ leo/cli/commands/run.rs | 2 ++ 4 files changed, 47 insertions(+), 13 deletions(-) mode change 100644 => 100755 .circleci/leo-example.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d56eeff1b1..8b41b60fc5 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -126,6 +126,19 @@ jobs: export LEO=/home/circleci/project/project/bin/leo ./project/.circleci/leo-clean.sh + leo-example: + docker: + - image: cimg/rust:1.71 + resource_class: xlarge + steps: + - attach_workspace: + at: /home/circleci/project/ + - run: + name: leo example + command: | + export LEO=/home/circleci/project/project/bin/leo + ./project/.circleci/leo-example.sh + test-examples: docker: - image: cimg/rust:1.71 @@ -153,6 +166,9 @@ workflows: - leo-clean: requires: - leo-executable + - leo-example: + requires: + - leo-executable - test-examples: requires: - leo-executable diff --git a/.circleci/leo-example.sh b/.circleci/leo-example.sh old mode 100644 new mode 100755 index d0d735ee09..d757fb4324 --- a/.circleci/leo-example.sh +++ b/.circleci/leo-example.sh @@ -6,6 +6,9 @@ # Run the play function. $LEO run play || exit + + # Execute the play function. + $LEO execute play || exit ) ( @@ -17,8 +20,11 @@ # Create a new game. $LEO run new || exit - # Create a make a move. + # Run the make_move function. $LEO run make_move || exit + + # Execute the make_move function. + $LEO execute make_move || exit ) ( @@ -29,4 +35,7 @@ # Run the mint_public function. $LEO run mint_public || exit + + # Execute the mint_public function. + $LEO execute mint_public || exit ) diff --git a/leo/cli/commands/execute.rs b/leo/cli/commands/execute.rs index 10fc152c6f..2df5b01510 100644 --- a/leo/cli/commands/execute.rs +++ b/leo/cli/commands/execute.rs @@ -27,8 +27,13 @@ pub struct Execute { #[clap(name = "INPUTS", help = "The inputs to the program. If none are provided, the input file is used.")] inputs: Vec, - #[clap(name = "ENDPOINT", help = "The specified network endpoint")] - endpoint: Option, + #[clap( + name = "ENDPOINT", + help = "The specified network endpoint.", + default_value = "https://api.explorer.aleo.org/v1", + long + )] + endpoint: String, #[clap(flatten)] pub(crate) compiler_options: BuildOptions, @@ -59,8 +64,19 @@ impl Command for Execute { // Compose the `execute` command. let mut arguments = vec![SNARKVM_COMMAND.to_string(), self.name]; + + // Add the program inputs to the arguments. arguments.append(&mut inputs); + // Add the compiler options to the arguments. + if self.compiler_options.offline { + arguments.push(String::from("--offline")); + } + + // Add the endpoint to the arguments. + arguments.push(String::from("--endpoint")); + arguments.push(self.endpoint); + // Open the Leo build/ directory let path = context.dir()?; let build_directory = BuildDirectory::open(&path)?; @@ -69,19 +85,10 @@ impl Command for Execute { std::env::set_current_dir(&build_directory) .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?; - // Call the `execute` command. - if self.compiler_options.offline { - arguments.push(String::from("--offline")); - } - - if self.endpoint.is_some() { - arguments.push(String::from("--endpoint")); - arguments.push(self.endpoint.unwrap()); - } - // Unset the Leo panic hook let _ = std::panic::take_hook(); + // Call the `execute` command. println!(); let command = SnarkVMExecute::try_parse_from(&arguments).map_err(CliError::failed_to_parse_execute)?; let res = command.parse().map_err(CliError::failed_to_execute_execute)?; diff --git a/leo/cli/commands/run.rs b/leo/cli/commands/run.rs index b993d87c85..ec27f4d812 100644 --- a/leo/cli/commands/run.rs +++ b/leo/cli/commands/run.rs @@ -56,6 +56,8 @@ impl Command for Run { // Compose the `run` command. let mut arguments = vec![SNARKVM_COMMAND.to_string(), self.name]; + + // Add the program inputs to the arguments. arguments.append(&mut inputs); // Open the Leo build/ directory