@@ -21,6 +21,7 @@ use clap_complete::{generate, Generator, Shell};
2121use fvm_shared:: econ:: TokenAmount ;
2222use ipc_sdk:: ethers_address_to_fil_address;
2323
24+ use fvm_shared:: address:: set_current_network;
2425use ipc_provider:: config:: { Config , Subnet } ;
2526use ipc_sdk:: subnet_id:: SubnetID ;
2627use std:: fmt:: Debug ;
@@ -65,6 +66,23 @@ struct IPCAgentCliCommands {
6566 command : Option < Commands > ,
6667}
6768
69+ /// A version of options that does partial matching on the arguments, with its only interest
70+ /// being the capture of global parameters that need to take effect first, before we parse [Options],
71+ /// because their value affects how others arse parsed.
72+ ///
73+ /// This one doesn't handle `--help` or `help` so that it is passed on to the next parser,
74+ /// where the full set of commands and arguments can be printed properly.
75+ #[ derive( Parser , Debug ) ]
76+ #[ command( version, disable_help_flag = true ) ]
77+ struct GlobalOptions {
78+ #[ command( flatten) ]
79+ global_params : GlobalArguments ,
80+
81+ /// Capture all the normal commands, basically to ingore them.
82+ #[ arg( allow_hyphen_values = true , trailing_var_arg = true ) ]
83+ pub cmd : Vec < String > ,
84+ }
85+
6886/// The `cli` method exposed to handle all the cli commands, ideally from main.
6987///
7088/// # Examples
@@ -94,6 +112,9 @@ struct IPCAgentCliCommands {
94112/// }
95113/// ```
96114pub async fn cli ( ) -> anyhow:: Result < ( ) > {
115+ let global = GlobalOptions :: parse ( ) ;
116+ set_current_network ( global. global_params . network ) ;
117+
97118 // parse the arguments
98119 let args = IPCAgentCliCommands :: parse ( ) ;
99120
0 commit comments