Skip to content

Commit

Permalink
cairo1-run CLI: Allow loading arguments from file (#1739)
Browse files Browse the repository at this point in the history
* Accept args from file

* Add doc

* Add changelog entry

---------

Co-authored-by: Pedro Fontana <[email protected]>
  • Loading branch information
fmoletta and pefontana authored Apr 30, 2024
1 parent 73e188d commit 6c554e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* `cairo1-run` CLI: Allow loading arguments from file[#1739](https://github.com/lambdaclass/cairo-vm/pull/1739)

* BREAKING: Remove unused `CairoRunner` field `original_steps`[#1742](https://github.com/lambdaclass/cairo-vm/pull/1742)

* feat: Add `--run_from_cairo_pie` to `cairo-vm-cli` + workflow [#1730](https://github.com/lambdaclass/cairo-vm/pull/1730)
Expand Down
2 changes: 2 additions & 0 deletions cairo1-run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ The cairo1-run cli supports the following optional arguments:

* `--args <ARGUMENTS>`: Receives the arguments to be passed to the program's main function. Receives whitespace-separated values which can be numbers or arrays, with arrays consisting of whitespace-separated numbers wrapped between brackets

* `--args_file <FILENAME>`: Receives the name of the file from where arguments should be read. Expects the same argument format of the `--args` flag. Should be used if the list of arguments exceeds the shell's capacity.

* `--trace_file <TRACE_FILE>`: Receives the name of a file and outputs the relocated trace into it

* `--memory_file <MEMORY_FILE>`: Receives the name of a file and outputs the relocated memory into it
Expand Down
10 changes: 8 additions & 2 deletions cairo1-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ struct Args {
cairo_pie_output: Option<PathBuf>,
// Arguments should be spaced, with array elements placed between brackets
// For example " --args '1 2 [1 2 3]'" will yield 3 arguments, with the last one being an array of 3 elements
#[clap(long = "args", default_value = "", value_parser=process_args)]
#[clap(long = "args", default_value = "", value_parser=process_args, conflicts_with = "args_file")]
args: FuncArgs,
// Same rules from `args` apply here
#[clap(long = "args_file", value_parser, value_hint=ValueHint::FilePath, conflicts_with = "args")]
args_file: Option<PathBuf>,
#[clap(long = "print_output", value_parser)]
print_output: bool,
#[clap(
Expand Down Expand Up @@ -129,7 +132,10 @@ impl FileWriter {
}

fn run(args: impl Iterator<Item = String>) -> Result<Option<String>, Error> {
let args = Args::try_parse_from(args)?;
let mut args = Args::try_parse_from(args)?;
if let Some(filename) = args.args_file {
args.args = process_args(&std::fs::read_to_string(filename)?).unwrap();
}

let cairo_run_config = Cairo1RunConfig {
proof_mode: args.proof_mode,
Expand Down

0 comments on commit 6c554e7

Please sign in to comment.