Skip to content

Commit 241d69d

Browse files
zahorodnyiikripaka
authored andcommitted
Initial draft version
1 parent 416f5bf commit 241d69d

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

nostr_options_cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ tokio-tungstenite = { workspace = true }
1010
futures-util = { workspace = true }
1111
serde_json = { workspace = true }
1212
tokio = { workspace = true }
13+
clap = {version = "4.5", features = ["derive"]}
14+
dirs = "6.0"

nostr_options_cli/src/main.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,112 @@
11
use global_utils::logger::init_logger;
22
use 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+
356

457
#[tokio::main]
558
async fn main() -> Result<()> {
659
let _logger_guard = init_logger();
760

61+
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+
}
97+
898
Ok(())
999
}
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

Comments
 (0)