@@ -29,19 +29,28 @@ def rpc_call(rpc_method, params: Optional[Union[Dict[str, Any], Tuple[Any, ...]]
2929def cli ():
3030 pass
3131
32+
3233@click .group (name = "debug" )
3334def debug ():
3435 """Debug commands"""
36+
37+
3538cli .add_command (debug )
3639
40+
3741@click .group (name = "scenarios" )
3842def scenarios ():
3943 """Scenario commands"""
44+
45+
4046cli .add_command (scenarios )
4147
48+
4249@click .group (name = "network" )
4350def network ():
4451 """Network commands"""
52+
53+
4554cli .add_command (network )
4655
4756
@@ -69,31 +78,42 @@ def help_command(ctx, command):
6978 help_info = cmd_obj .get_help (ctx ).split ("\n " , 1 )[- 1 ].strip ()
7079
7180 # Extract the arguments of the command
72- arguments = [param .human_readable_name .upper () for param in cmd_obj .params if isinstance (param , click .Argument )]
81+ arguments = [
82+ param .human_readable_name .upper ()
83+ for param in cmd_obj .params
84+ if isinstance (param , click .Argument )
85+ ]
7386
7487 # Determine the correct usage string based on whether the command has subcommands
7588 if isinstance (cmd_obj , click .Group ) and cmd_obj .list_commands (ctx ):
76- usage_str = f"Usage: warnet { command } [OPTIONS] COMMAND [ARGS...]\n \n { help_info } "
89+ usage_str = (
90+ f"Usage: warnet { command } [OPTIONS] COMMAND [ARGS...]\n \n { help_info } "
91+ )
7792 else :
7893 args_str = " " .join (arguments )
7994 usage_str = f"Usage: warnet { command } [OPTIONS] { args_str } \n \n { help_info } "
80-
95+
8196 print (usage_str )
8297
98+
8399cli .add_command (help_command )
84100
85101
86102@cli .command (context_settings = {"ignore_unknown_options" : True })
87- @click .argument ('node' , type = int )
88- @click .argument ('method' , type = str , nargs = - 1 ) # this will capture all remaining arguments
89- @click .option ('--params' , type = str , multiple = True , default = ())
90- @click .option ('--network' , default = 'warnet' , show_default = True )
103+ @click .argument ("node" , type = int )
104+ @click .argument (
105+ "method" , type = str , nargs = - 1
106+ ) # this will capture all remaining arguments
107+ @click .option ("--params" , type = str , multiple = True , default = ())
108+ @click .option ("--network" , default = "warnet" , show_default = True )
91109def rpc (node , method , params , network ):
92110 """
93111 Call bitcoin-cli <method> <params> on <node> in <--network>
94112 """
95113 if len (method ) > 2 :
96- raise click .BadArgumentUsage ("You can provide at most two arguments for 'method'." )
114+ raise click .BadArgumentUsage (
115+ "You can provide at most two arguments for 'method'."
116+ )
97117
98118 # Convert tuple to space-separated string
99119 method_str = " " .join (method )
@@ -109,8 +129,8 @@ def rpc(node, method, params, network):
109129
110130
111131@cli .command ()
112- @click .argument (' node' , type = int , required = True )
113- @click .option (' --network' , default = ' warnet' , show_default = True )
132+ @click .argument (" node" , type = int , required = True )
133+ @click .option (" --network" , default = " warnet" , show_default = True )
114134def debug_log (node , network ):
115135 """
116136 Fetch the Bitcoin Core debug log from <node> in [network]
@@ -123,14 +143,15 @@ def debug_log(node, network):
123143
124144
125145@cli .command ()
126- @click .argument (' node_a' , type = int , required = True )
127- @click .argument (' node_b' , type = int , required = True )
128- @click .option (' --network' , default = ' warnet' , show_default = True )
146+ @click .argument (" node_a" , type = int , required = True )
147+ @click .argument (" node_b" , type = int , required = True )
148+ @click .option (" --network" , default = " warnet" , show_default = True )
129149def messages (node_a , node_b , network ):
130150 """
131151 Fetch messages sent between <node_a> and <node_b> in <network>
132152 """
133153 import logging
154+
134155 logging .warning (f"got args: { node_a } , { node_b } , { network } " )
135156 try :
136157 result = rpc_call (
@@ -156,7 +177,7 @@ def list():
156177
157178
158179@scenarios .command ()
159- @click .argument (' scenario' , type = str )
180+ @click .argument (" scenario" , type = str )
160181def run (scenario ):
161182 """
162183 Run <scenario> from the Warnet Test Framework
@@ -169,49 +190,59 @@ def run(scenario):
169190
170191
171192@debug .command ()
172- @click .argument (' graph_file' , type = str )
173- @click .option (' --network' , default = ' warnet' , show_default = True )
193+ @click .argument (" graph_file" , type = str )
194+ @click .option (" --network" , default = " warnet" , show_default = True )
174195def generate_compose (graph_file : str , network : str = "warnet" ):
175196 """
176197 Generate the docker-compose file for a given <graph_file> and <--network> name and return it.
177198 """
178199 try :
179- result = rpc_call ("generate_compose" , {"graph_file" : graph_file , "network" : network })
200+ result = rpc_call (
201+ "generate_compose" , {"graph_file" : graph_file , "network" : network }
202+ )
180203 print (result )
181204 except Exception as e :
182205 print (f"Error generating compose: { e } " )
183206
207+
184208@debug .command ()
185- @click .argument (' graph_file' , type = str )
186- @click .option (' --network' , default = ' warnet' , show_default = True )
209+ @click .argument (" graph_file" , type = str )
210+ @click .option (" --network" , default = " warnet" , show_default = True )
187211def update_dns_seed (graph_file : Path = EXAMPLE_GRAPH_FILE , network : str = "warnet" ):
188212 """
189213 Update the dns seed database using a graph file
190214 """
191215 try :
192- result = rpc_call ("update_dns_seeder" , {"graph_file" : str (graph_file ), "network" : network })
216+ result = rpc_call (
217+ "update_dns_seeder" , {"graph_file" : str (graph_file ), "network" : network }
218+ )
193219 print (result )
194220 except Exception as e :
195221 print (f"Error updating dns seed addresses: { e } " )
196222
197223
198224@network .command ()
199- @click .argument ('graph_file' , default = EXAMPLE_GRAPH_FILE , type = click .Path ())
200- @click .option ('--force' , default = False , is_flag = True , type = bool )
201- @click .option ('--network' , default = 'warnet' , show_default = True )
202- def start (graph_file : Path = EXAMPLE_GRAPH_FILE , force : bool = False , network : str = "warnet" ):
225+ @click .argument ("graph_file" , default = EXAMPLE_GRAPH_FILE , type = click .Path ())
226+ @click .option ("--force" , default = False , is_flag = True , type = bool )
227+ @click .option ("--network" , default = "warnet" , show_default = True )
228+ def start (
229+ graph_file : Path = EXAMPLE_GRAPH_FILE , force : bool = False , network : str = "warnet"
230+ ):
203231 """
204232 Start a warnet with topology loaded from a <graph_file> into <--network> (default: "warnet")
205233 """
206234 try :
207- result = rpc_call ("from_file" , {"graph_file" : str (graph_file ), "force" : force , "network" : network })
235+ result = rpc_call (
236+ "from_file" ,
237+ {"graph_file" : str (graph_file ), "force" : force , "network" : network },
238+ )
208239 print (result )
209240 except Exception as e :
210241 print (f"Error creating network: { e } " )
211242
212243
213244@network .command ()
214- @click .option (' --network' , default = ' warnet' , show_default = True )
245+ @click .option (" --network" , default = " warnet" , show_default = True )
215246def up (network : str = "warnet" ):
216247 """
217248 Run 'docker-compose up' on a warnet named <--network> (default: "warnet").
@@ -224,7 +255,7 @@ def up(network: str = "warnet"):
224255
225256
226257@network .command ()
227- @click .option (' --network' , default = ' warnet' , show_default = True )
258+ @click .option (" --network" , default = " warnet" , show_default = True )
228259def down (network : str = "warnet" ):
229260 """
230261 Run 'docker-compose down on a warnet named <--network> (default: "warnet").
0 commit comments