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
This commit is contained in:
Collin Chin 2023-08-15 13:59:50 -07:00 committed by GitHub
parent 85d9a28ebb
commit 700e31f113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 13 deletions

View File

@ -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

11
.circleci/leo-example.sh Normal file → Executable file
View File

@ -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
)

View File

@ -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<String>,
#[clap(name = "ENDPOINT", help = "The specified network endpoint")]
endpoint: Option<String>,
#[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)?;

View File

@ -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