From 6c554e72be19a18d1ffe71e38f6d614c2a4d742f Mon Sep 17 00:00:00 2001 From: fmoletta <99273364+fmoletta@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:43:23 -0300 Subject: [PATCH] `cairo1-run` CLI: Allow loading arguments from file (#1739) * Accept args from file * Add doc * Add changelog entry --------- Co-authored-by: Pedro Fontana --- CHANGELOG.md | 2 ++ cairo1-run/README.md | 2 ++ cairo1-run/src/main.rs | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d3af62faf..4a68ff2657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cairo1-run/README.md b/cairo1-run/README.md index 3402401fe2..9654e91747 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -55,6 +55,8 @@ The cairo1-run cli supports the following optional arguments: * `--args `: 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 `: 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 `: Receives the name of a file and outputs the relocated trace into it * `--memory_file `: Receives the name of a file and outputs the relocated memory into it diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 7fd1754da5..5ca02bda21 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -44,8 +44,11 @@ struct Args { cairo_pie_output: Option, // 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, #[clap(long = "print_output", value_parser)] print_output: bool, #[clap( @@ -129,7 +132,10 @@ impl FileWriter { } fn run(args: impl Iterator) -> Result, 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,