1
- use bitcoin:: Network ;
2
1
use clap:: { Parser , Subcommand } ;
3
- use clementine_cli:: { config:: CliConfig , deposit, withdrawal} ;
2
+ use clementine_cli:: { config:: CliConfig , debug, deposit, withdrawal} ;
3
+ use std:: path:: PathBuf ;
4
4
5
5
#[ derive( Parser ) ]
6
6
#[ command( name = "clementine" ) ]
7
7
#[ command( about = "Clementine CLI - wallet-agnostic Citrea bridge CLI" , long_about = None ) ]
8
8
struct Cli {
9
- /// Bitcoin network to use (bitcoin, testnet, testnet4)
10
- #[ arg( long, default_value = "bitcoin" ) ]
11
- network : String ,
9
+ /// Path to config file. If not given, current directory will be searched for the cli_config.toml file
10
+ #[ arg( long) ]
11
+ config_file : Option < PathBuf > ,
12
12
13
13
#[ command( subcommand) ]
14
14
command : Commands ,
15
15
}
16
16
17
17
#[ derive( Subcommand ) ]
18
18
enum Commands {
19
+ /// Deposit related operations.
19
20
Deposit {
20
21
#[ command( subcommand) ]
21
22
command : DepositCommands ,
22
23
} ,
24
+ /// Withdrawal related operations.
23
25
Withdrawal {
24
26
#[ command( subcommand) ]
25
27
command : WithdrawalCommands ,
@@ -132,23 +134,20 @@ enum WithdrawalCommands {
132
134
async fn main ( ) {
133
135
let cli = Cli :: parse ( ) ;
134
136
135
- // Parse network string using bitcoin crate's parsing
136
- let network = match cli. network . parse :: < Network > ( ) {
137
- Ok ( network) => network,
138
- Err ( _) => {
139
- eprintln ! (
140
- "Error: Invalid network '{}'. Use: bitcoin, testnet, signet, regtest or testnet4" ,
141
- cli. network
142
- ) ;
143
- std:: process:: exit ( 1 ) ;
144
- }
137
+ let config = if let Some ( config_file_path) = cli. config_file {
138
+ debug ! ( "Config file {config_file_path:?} is going to be used..." ) ;
139
+ CliConfig :: try_parse_file ( config_file_path) . unwrap ( )
140
+ } else {
141
+ let mut current_dir = std:: env:: current_dir ( ) . unwrap ( ) ;
142
+ current_dir. push ( "cli_config.toml" ) ;
143
+ debug ! ( "No config file given, looking for the current directory: {current_dir:?}..." ) ;
144
+ CliConfig :: try_parse_file ( current_dir) . unwrap ( )
145
145
} ;
146
- let config = CliConfig :: from_network ( network) ;
147
146
148
147
match cli. command {
149
148
Commands :: Deposit { command } => match command {
150
149
DepositCommands :: GenerateRecoveryKey { y, private_key } => {
151
- if let Err ( e) = deposit:: generate_recovery_key ( y, private_key, network) {
150
+ if let Err ( e) = deposit:: generate_recovery_key ( y, private_key, config . network ) {
152
151
eprintln ! ( "Error: {}" , e) ;
153
152
std:: process:: exit ( 1 ) ;
154
153
}
@@ -229,7 +228,7 @@ async fn main() {
229
228
} ,
230
229
Commands :: Withdrawal { command } => match command {
231
230
WithdrawalCommands :: GenerateSignerAddress { y } => {
232
- if let Err ( e) = withdrawal:: generate_signer_address ( y, network) {
231
+ if let Err ( e) = withdrawal:: generate_signer_address ( y, config . network ) {
233
232
eprintln ! ( "Error: {}" , e) ;
234
233
std:: process:: exit ( 1 ) ;
235
234
}
@@ -245,7 +244,7 @@ async fn main() {
245
244
& withdrawal_address,
246
245
& withdrawal_utxo,
247
246
amount,
248
- network,
247
+ config . network ,
249
248
) {
250
249
eprintln ! ( "Error: {}" , e) ;
251
250
std:: process:: exit ( 1 ) ;
0 commit comments