@@ -37,29 +37,26 @@ pub type Balance = u64;
3737pub type Nonce = u32 ;
3838pub type RefCount = u32 ;
3939
40- fn generate_replica_spec ( gen_replica : flags:: GenReplica , out : PathBuf , sudo : Option < String > ) {
41- // Create a temporary directory
42- let temp_dir = tempfile:: Builder :: new ( )
43- . prefix ( "torus-replica-spec" )
44- . tempdir ( )
45- . expect ( "failed to create tempdir" )
46- . into_path ( ) ;
47-
40+ fn generate_replica_spec (
41+ gen_replica : flags:: GenReplica ,
42+ out : Option < PathBuf > ,
43+ sudo : Option < String > ,
44+ ) {
4845 // Create Replica command
4946 let replica_cmd = flags:: Replica {
50- output : Some ( out) ,
47+ output : out,
5148 sudo,
5249 api_url : gen_replica. api_url . clone ( ) ,
5350 } ;
5451
5552 // Call the targetchain_spec function
56- targetchain_spec ( & replica_cmd, & temp_dir ) ;
53+ targetchain_spec ( & replica_cmd) ;
5754
5855 // The file is already written by targetchain_spec, no need to write again
5956}
6057
6158/// Function moved from build_spec.rs
62- pub fn targetchain_spec ( flags : & flags:: Replica , dir : & Path ) -> PathBuf {
59+ pub fn targetchain_spec ( flags : & flags:: Replica ) -> Option < PathBuf > {
6360 let spec = tokio:: runtime:: Builder :: new_multi_thread ( )
6461 . enable_all ( )
6562 . build ( )
@@ -78,13 +75,16 @@ pub fn targetchain_spec(flags: &flags::Replica, dir: &Path) -> PathBuf {
7875
7976 let js = serde_json:: to_string_pretty ( & js) . unwrap ( ) ;
8077
81- let chain_path = flags
82- . output
83- . clone ( )
84- . unwrap_or_else ( || dir. join ( "spec.json" ) ) ;
85- std:: fs:: write ( & chain_path, js) . unwrap ( ) ;
86-
87- chain_path
78+ match & flags. output {
79+ Some ( chain_path) => {
80+ std:: fs:: write ( chain_path, js) . unwrap ( ) ;
81+ Some ( chain_path. clone ( ) )
82+ }
83+ None => {
84+ println ! ( "{js}" ) ;
85+ None
86+ }
87+ }
8888}
8989
9090/// Sets the sudo key in the genesis state
@@ -264,9 +264,16 @@ fn generate_new_spec(gen_new: &flags::GenNew, cmd: &flags::GenerateSpec) {
264264 customize_spec ( & mut json, cmd) ;
265265
266266 // Write the result to the output file
267- let serialized = serde_json:: to_vec ( & json) . expect ( "failed to generate spec file" ) ;
267+ let serialized = serde_json:: to_string_pretty ( & json) . expect ( "failed to generate spec file" ) ;
268268
269- std:: fs:: write ( & cmd. out , serialized) . expect ( "failed to write resulting spec file" ) ;
269+ match & cmd. out {
270+ Some ( output_path) => {
271+ std:: fs:: write ( output_path, serialized) . expect ( "failed to write resulting spec file" ) ;
272+ }
273+ None => {
274+ println ! ( "{serialized}" ) ;
275+ }
276+ }
270277}
271278
272279// Function to customize a spec file based on the provided flags
0 commit comments