diff --git a/sdk/src/run/mod.rs b/sdk/src/run/mod.rs index a3c7653..c36e6d9 100644 --- a/sdk/src/run/mod.rs +++ b/sdk/src/run/mod.rs @@ -48,6 +48,14 @@ pub fn run_cli_on_scaffold< >( cli: AxiomCircuitRunnerOptions, ) { + match cli.command { + SnarkCmd::WitnessGen => {} + _ => { + if cli.to_stdout { + panic!("The `to_stdout` argument is only valid for the `witness-gen` command."); + } + } + } match cli.command { SnarkCmd::Mock | SnarkCmd::Prove | SnarkCmd::WitnessGen => { if cli.input_path.is_none() { @@ -236,7 +244,11 @@ pub fn run_cli_on_scaffold< } SnarkCmd::WitnessGen => { let output = witness_gen(&mut runner); - write_witness_gen_output(output, cli.data_path.join(PathBuf::from("compute.json"))); + write_witness_gen_output( + output, + cli.data_path.join(PathBuf::from("compute.json")), + cli.to_stdout, + ); } } } diff --git a/sdk/src/run/readme.md b/sdk/src/run/readme.md index 5b9931c..09dcb72 100644 --- a/sdk/src/run/readme.md +++ b/sdk/src/run/readme.md @@ -18,9 +18,10 @@ Options: -n, --name Name of the output metadata file [default: circuit] -d, --data-path For saving build artifacts [default: data] -c, --config For specifying custom circuit parameters - --srs For specifying custom KZG params directory [default: params] - --aggregate Whether to aggregate the output (defaults to false) - --auto-config-aggregation Whether to aggregate the output (defaults to false) + --srs For specifying custom KZG params directory + --aggregate Whether to aggregate the output [default: false] + --auto-config-aggregation Whether to aggregate the output [default: false] + -s, --to-stdout (witness-gen only) Output to stdout (true) or json (false) [default: false] -h, --help Print help -V, --version Print version ``` \ No newline at end of file diff --git a/sdk/src/run/types.rs b/sdk/src/run/types.rs index ea2e46e..44fd413 100644 --- a/sdk/src/run/types.rs +++ b/sdk/src/run/types.rs @@ -91,7 +91,7 @@ pub struct AxiomCircuitRunnerOptions { #[arg( long = "aggregate", - help = "Whether to aggregate the output (defaults to false)", + help = "Whether to aggregate the output [default: false]", action )] /// Whether to aggregate the output @@ -99,9 +99,18 @@ pub struct AxiomCircuitRunnerOptions { #[arg( long = "auto-config-aggregation", - help = "Whether to aggregate the output (defaults to false)", + help = "Whether to aggregate the output [default: false]", action )] /// Whether to auto calculate the aggregation params pub should_auto_config_aggregation_circuit: bool, + + #[arg( + short = 's', + long = "to-stdout", + help = "(witness-gen only) Output to stdout (true) or json (false) [default: false]", + action + )] + /// Whether to output to stdout (true) or json file (false) + pub to_stdout: bool, } diff --git a/sdk/src/utils/io.rs b/sdk/src/utils/io.rs index 9092045..94f2f68 100644 --- a/sdk/src/utils/io.rs +++ b/sdk/src/utils/io.rs @@ -203,15 +203,21 @@ pub fn write_output( info!("Writing JSON output to {:?}", &json_output_path); let f = File::create(&json_output_path) .unwrap_or_else(|_| panic!("Could not create file at {json_output_path:?}")); - serde_json::to_writer_pretty(&f, &output).expect("Writing output should not fail"); + + serde_json::to_writer_pretty(&f, &output).expect("Writing output should not fail"); } pub fn write_witness_gen_output( output: AxiomV2DataAndResults, json_output_path: PathBuf, + to_stdout: bool, ) { - info!("Writing JSON output to {:?}", &json_output_path); - let f = File::create(&json_output_path) + if to_stdout { + serde_json::to_writer_pretty(&std::io::stdout(), &output.compute_results).expect("Writing output should not fail"); + } else { + info!("Writing JSON output to {:?}", &json_output_path); + let f = File::create(&json_output_path) .unwrap_or_else(|_| panic!("Could not create file at {json_output_path:?}")); - serde_json::to_writer_pretty(&f, &output.compute_results).expect("Writing output should not fail"); + serde_json::to_writer_pretty(&f, &output.compute_results).expect("Writing output should not fail"); + } } \ No newline at end of file