1+ use clap:: Parser ;
12use global_utils:: logger:: init_logger;
23use nostr:: prelude:: * ;
3- use clap:: { Parser , Subcommand } ;
4- use std:: path:: PathBuf ;
5-
6-
7- #[ derive( Parser ) ]
8- struct Cli {
9- #[ command( subcommand) ]
10- command : Command
11- }
12-
13- #[ derive( Debug , Subcommand ) ]
14- enum Command {
15- /// Maker
16- CreateOrder {
17- #[ arg( short = 'm' , long) ]
18- message : String ,
19-
20- #[ arg( short = 'k' , long) ]
21- key_path : Option < PathBuf > ,
22-
23- #[ arg( short = 'r' , long) ]
24- relays_path : Option < PathBuf > ,
25- } ,
26-
27- GetOrderReply {
28- #[ arg( short = 'i' , long) ]
29- id : String ,
30-
31- #[ arg( short = 'k' , long) ]
32- key_path : Option < PathBuf > ,
33-
34- #[ arg( short = 'r' , long) ]
35- relays_path : Option < PathBuf > ,
36- } ,
37-
38- /// Taker
39- ListOrders {
40- #[ arg( short = 'k' , long) ]
41- key_path : Option < PathBuf > ,
42-
43- #[ arg( short = 'r' , long) ]
44- relays_path : Option < PathBuf > ,
45- } ,
46-
47- ReplyOrder {
48- #[ arg( short = 'i' , long) ]
49- id : String ,
50-
51- #[ arg( short = 'k' , long) ]
52- key_path : Option < PathBuf > ,
53- } ,
54- }
55-
4+ use nostr_options_cli:: cli_processor:: Cli ;
565
576#[ tokio:: main]
587async fn main ( ) -> Result < ( ) > {
598 let _logger_guard = init_logger ( ) ;
609
6110 let cli = Cli :: parse ( ) ;
62-
63- match cli. command {
64- Command :: CreateOrder { message, key_path, relays_path } => {
65- let key_path = key_path. unwrap_or ( default_key_path ( ) ) ;
66- let relays_path = relays_path. unwrap_or ( default_relays_path ( ) ) ;
67- println ! ( "🛠 Create order:" ) ;
68- println ! ( " message: {}" , message) ;
69- println ! ( " key_path: {}" , key_path. display( ) ) ;
70- println ! ( " relays_path: {}" , relays_path. display( ) ) ;
71- }
72-
73- Command :: GetOrderReply { id, key_path, relays_path } => {
74- let key_path = key_path. unwrap_or ( default_key_path ( ) ) ;
75- let relays_path = relays_path. unwrap_or ( default_relays_path ( ) ) ;
76- println ! ( "📦 Get order reply:" ) ;
77- println ! ( " id: {}" , id) ;
78- println ! ( " key_path: {}" , key_path. display( ) ) ;
79- println ! ( " relays_path: {}" , relays_path. display( ) ) ;
80- }
81-
82- Command :: ListOrders { key_path, relays_path } => {
83- let key_path = key_path. unwrap_or ( default_key_path ( ) ) ;
84- let relays_path = relays_path. unwrap_or ( default_relays_path ( ) ) ;
85- println ! ( "📋 List orders:" ) ;
86- println ! ( " key_path: {}" , key_path. display( ) ) ;
87- println ! ( " relays_path: {}" , relays_path. display( ) ) ;
88- }
89-
90- Command :: ReplyOrder { id, key_path } => {
91- let key_path = key_path. unwrap_or ( default_key_path ( ) ) ;
92- println ! ( "💬 Reply order:" ) ;
93- println ! ( " id: {}" , id) ;
94- println ! ( " key_path: {}" , key_path. display( ) ) ;
95- }
96- }
11+ cli. process ( ) ?;
9712
9813 Ok ( ( ) )
9914}
100-
101-
102- fn default_key_path ( ) -> PathBuf {
103- dirs:: home_dir ( )
104- . unwrap_or_else ( || PathBuf :: from ( "." ) )
105- . join ( ".nostr/keypair.txt" )
106- }
107-
108- fn default_relays_path ( ) -> PathBuf {
109- dirs:: home_dir ( )
110- . unwrap_or_else ( || PathBuf :: from ( "." ) )
111- . join ( ".nostr/relays.txt" )
112- }
0 commit comments