1
1
//! Coffee command line arguments definition.
2
2
use clap:: { Parser , Subcommand } ;
3
+ use coffee_lib:: { error, errors:: CoffeeError } ;
3
4
4
5
/// Coffee main command line definition for the command line tools.
5
6
#[ derive( Debug , Parser ) ]
@@ -133,6 +134,36 @@ impl From<&RemoteAction> for coffee_core::RemoteAction {
133
134
}
134
135
}
135
136
137
+ #[ derive( Debug ) ]
138
+ enum ClnNetwork {
139
+ Mainnet ,
140
+ Testnet ,
141
+ Signet ,
142
+ Regtest ,
143
+ }
144
+
145
+ impl ClnNetwork {
146
+ fn from_str ( network : & str ) -> Option < Self > {
147
+
148
+ match network {
149
+ "mainnet" => Some ( Self :: Mainnet ) ,
150
+ "testnet" => Some ( Self :: Testnet ) ,
151
+ "signet" => Some ( Self :: Signet ) ,
152
+ "regtest" => Some ( Self :: Regtest ) ,
153
+ _ => None ,
154
+ }
155
+ }
156
+
157
+ fn to_str ( network : Self ) -> Option < String > {
158
+ match network {
159
+ Self :: Mainnet => Some ( "mainnet" . to_string ( ) ) ,
160
+ Self :: Testnet => Some ( "testnet" . to_string ( ) ) ,
161
+ Self :: Signet => Some ( "signet" . to_string ( ) ) ,
162
+ Self :: Regtest => Some ( "regtest" . to_string ( ) ) ,
163
+ }
164
+ }
165
+ }
166
+
136
167
impl coffee_core:: CoffeeArgs for CoffeeArgs {
137
168
fn command ( & self ) -> coffee_core:: CoffeeOperation {
138
169
coffee_core:: CoffeeOperation :: from ( & self . command )
@@ -147,7 +178,10 @@ impl coffee_core::CoffeeArgs for CoffeeArgs {
147
178
}
148
179
149
180
fn network ( & self ) -> Option < String > {
150
- self . network . clone ( )
181
+ let network = self . network . clone ( ) . ok_or_else ( || error ! ( "Network is not set" ) ) . ok ( ) ?;
182
+ let validated_network = ClnNetwork :: from_str ( & network. to_lowercase ( ) ) . ok_or_else ( || error ! ( "Invalid network name" ) ) . ok ( ) ?;
183
+
184
+ ClnNetwork :: to_str ( validated_network)
151
185
}
152
186
153
187
fn skip_verify ( & self ) -> bool {
0 commit comments