Skip to content

Commit

Permalink
Rename 'program input' to 'arguments' and document this feature
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Kaput <[email protected]>
  • Loading branch information
mkaput committed Jan 22, 2024
1 parent 4248f46 commit a5ec49e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions extensions/scarb-cairo-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ struct Args {
#[arg(long, default_value_t = false)]
no_build: bool,

/// Input to the program.
/// Program arguments.
///
/// This should be a JSON array of numbers, decimal bigints or recursive arrays of those. For example, pass `[1]`
/// to the following function `fn main(a: u64)`, or pass `[1, "2"]` to `fn main(a: u64, b: u64)`,
/// or `[[1, 2], [3, 4, 5]]` to `fn main(t: (u64, u64), v: Array<u64>)`.
#[arg(default_value = "[]")]
program_input: deserialization::Args,
arguments: deserialization::Args,
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -101,7 +105,7 @@ fn main() -> Result<()> {
let result = runner
.run_function_with_starknet_context(
runner.find_function("::main")?,
&args.program_input,
&args.arguments,
available_gas.value(),
StarknetState::default(),
)
Expand Down
12 changes: 12 additions & 0 deletions website/docs/extensions/cairo-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ The first one is used to set the available gas for the execution.
If not provided, a gas usage is not limited.
Gas usage can be disallowed by setting the value to `0`.
The second one prints the full memory after the execution.

## Program arguments

The `main` function may take arguments. They can be passed to the `scarb cairo-run` command as a single JSON array of
numbers, decimal bigints or recursive arrays of those. Nested arrays can translate to either Cairo arrays, tuples or
plain structures. Consult the following table for example valid arguments and their matching function signatures:

| Argument | Function signature |
| --------------------- | --------------------------------------- |
| `[1]` | `fn main(a: u64)` |
| `[1, "2"]` | `fn main(a: u64, b: u64)` |
| `[[1, 2], [3, 4, 5]]` | `fn main(t: (u64, u64), v: Array<u64>)` |

0 comments on commit a5ec49e

Please sign in to comment.