Skip to content

Commit

Permalink
fix leo execute command line argument parsing (#2530)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
collinc97 authored Aug 15, 2023
1 parent 85d9a28 commit 700e31f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -153,6 +166,9 @@ workflows:
- leo-clean:
requires:
- leo-executable
- leo-example:
requires:
- leo-executable
- test-examples:
requires:
- leo-executable
11 changes: 10 additions & 1 deletion .circleci/leo-example.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

# Run the play function.
$LEO run play || exit

# Execute the play function.
$LEO execute play || exit
)

(
Expand All @@ -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
)

(
Expand All @@ -29,4 +35,7 @@

# Run the mint_public function.
$LEO run mint_public || exit

# Execute the mint_public function.
$LEO execute mint_public || exit
)
31 changes: 19 additions & 12 deletions leo/cli/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand All @@ -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)?;
Expand Down
2 changes: 2 additions & 0 deletions leo/cli/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 700e31f

Please sign in to comment.