Skip to content

Commit 6c554e7

Browse files
fmolettapefontana
andauthored
cairo1-run CLI: Allow loading arguments from file (#1739)
* Accept args from file * Add doc * Add changelog entry --------- Co-authored-by: Pedro Fontana <[email protected]>
1 parent 73e188d commit 6c554e7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* `cairo1-run` CLI: Allow loading arguments from file[#1739](https://github.com/lambdaclass/cairo-vm/pull/1739)
6+
57
* BREAKING: Remove unused `CairoRunner` field `original_steps`[#1742](https://github.com/lambdaclass/cairo-vm/pull/1742)
68

79
* feat: Add `--run_from_cairo_pie` to `cairo-vm-cli` + workflow [#1730](https://github.com/lambdaclass/cairo-vm/pull/1730)

cairo1-run/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ The cairo1-run cli supports the following optional arguments:
5555

5656
* `--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
5757

58+
* `--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.
59+
5860
* `--trace_file <TRACE_FILE>`: Receives the name of a file and outputs the relocated trace into it
5961

6062
* `--memory_file <MEMORY_FILE>`: Receives the name of a file and outputs the relocated memory into it

cairo1-run/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ struct Args {
4444
cairo_pie_output: Option<PathBuf>,
4545
// Arguments should be spaced, with array elements placed between brackets
4646
// For example " --args '1 2 [1 2 3]'" will yield 3 arguments, with the last one being an array of 3 elements
47-
#[clap(long = "args", default_value = "", value_parser=process_args)]
47+
#[clap(long = "args", default_value = "", value_parser=process_args, conflicts_with = "args_file")]
4848
args: FuncArgs,
49+
// Same rules from `args` apply here
50+
#[clap(long = "args_file", value_parser, value_hint=ValueHint::FilePath, conflicts_with = "args")]
51+
args_file: Option<PathBuf>,
4952
#[clap(long = "print_output", value_parser)]
5053
print_output: bool,
5154
#[clap(
@@ -129,7 +132,10 @@ impl FileWriter {
129132
}
130133

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

134140
let cairo_run_config = Cairo1RunConfig {
135141
proof_mode: args.proof_mode,

0 commit comments

Comments
 (0)