Skip to content

Commit e8ef999

Browse files
committed
cli: rename open command to shell
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 7b1aa62 commit e8ef999

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
* sdk: inherit pool subscriptions only when calling `Client::add_relay` or `Client::add_read_relay` methods ([Yuki Kishimoto])
7979
* ffi(nostr): impl `Display` for `Coordinate` ([Yuki Kishimoto])
8080
* ffi(sdk): change `Connection::embedded_tor` fingerprint for `android` and `ios` targets ([Yuki Kishimoto])
81+
* cli: rename `open` command to `shell` ([Yuki Kishimoto])
8182

8283
### Added
8384

crates/nostr-cli/src/cli/mod.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ pub mod parser;
1616
#[clap(author, version, about, long_about)]
1717
pub struct Cli {
1818
#[command(subcommand)]
19-
pub command: CliCommand,
19+
pub command: Command,
2020
}
2121

2222
#[derive(Debug, Subcommand)]
23-
pub enum CliCommand {
24-
Open {
23+
pub enum Command {
24+
/// Open nostr shell
25+
Shell {
2526
#[clap(long)]
2627
relays: Vec<Url>,
2728
// tor: bool,
@@ -37,7 +38,7 @@ pub enum CliCommand {
3738

3839
#[derive(Debug, Parser)]
3940
#[command(name = "")]
40-
pub enum Command {
41+
pub enum ShellCommand {
4142
/// Generate random keys
4243
Generate,
4344
/// Sync public key's event with specified relays (negentropy)
@@ -49,8 +50,8 @@ pub enum Command {
4950
#[clap(long)]
5051
relays: Vec<Url>,
5152
/// Direction
52-
#[clap(short, long, value_enum, default_value_t = CliNegentropyDirection::Down)]
53-
direction: CliNegentropyDirection,
53+
#[clap(short, long, value_enum, default_value_t = ShellNegentropyDirection::Down)]
54+
direction: ShellNegentropyDirection,
5455
},
5556
/// Query
5657
Query {
@@ -92,16 +93,14 @@ pub enum Command {
9293
#[command(arg_required_else_help = true)]
9394
Database {
9495
#[command(subcommand)]
95-
command: DatabaseCommand,
96+
command: ShellCommandDatabase,
9697
},
97-
/// Developer tools
98-
Dev {},
9998
/// Exit
10099
Exit,
101100
}
102101

103102
#[derive(Debug, Subcommand)]
104-
pub enum DatabaseCommand {
103+
pub enum ShellCommandDatabase {
105104
/// Populate database
106105
#[command(arg_required_else_help = true)]
107106
Populate {
@@ -112,11 +111,8 @@ pub enum DatabaseCommand {
112111
Stats,
113112
}
114113

115-
#[derive(Debug, Subcommand)]
116-
pub enum DevCommands {}
117-
118114
#[derive(Debug, Clone, ValueEnum)]
119-
pub enum CliNegentropyDirection {
115+
pub enum ShellNegentropyDirection {
120116
/// Send events to relay
121117
Up,
122118
/// Get events from relay
@@ -125,12 +121,12 @@ pub enum CliNegentropyDirection {
125121
Both,
126122
}
127123

128-
impl From<CliNegentropyDirection> for NegentropyDirection {
129-
fn from(value: CliNegentropyDirection) -> Self {
124+
impl From<ShellNegentropyDirection> for NegentropyDirection {
125+
fn from(value: ShellNegentropyDirection) -> Self {
130126
match value {
131-
CliNegentropyDirection::Up => Self::Up,
132-
CliNegentropyDirection::Down => Self::Down,
133-
CliNegentropyDirection::Both => Self::Both,
127+
ShellNegentropyDirection::Up => Self::Up,
128+
ShellNegentropyDirection::Down => Self::Down,
129+
ShellNegentropyDirection::Both => Self::Both,
134130
}
135131
}
136132
}

crates/nostr-cli/src/main.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tokio::time::Instant;
1616
mod cli;
1717
mod util;
1818

19-
use self::cli::{io, parser, Cli, CliCommand, Command, DatabaseCommand};
19+
use self::cli::{io, parser, Cli, Command, ShellCommand, ShellCommandDatabase};
2020

2121
#[tokio::main]
2222
async fn main() {
@@ -29,7 +29,7 @@ async fn run() -> Result<()> {
2929
let args = Cli::parse();
3030

3131
match args.command {
32-
CliCommand::Open { relays } => {
32+
Command::Shell { relays } => {
3333
let db = NostrLMDB::open("./db/nostr-lmdb")?;
3434
let client = Client::builder().database(db).build();
3535

@@ -49,7 +49,7 @@ async fn run() -> Result<()> {
4949
rl.add_history_entry(line.as_str())?;
5050
let mut vec: Vec<String> = parser::split(&line)?;
5151
vec.insert(0, String::new());
52-
match Command::try_parse_from(vec) {
52+
match ShellCommand::try_parse_from(vec) {
5353
Ok(command) => {
5454
if let Err(e) = handle_command(command, &client).await {
5555
eprintln!("Error: {e}");
@@ -75,7 +75,7 @@ async fn run() -> Result<()> {
7575

7676
Ok(())
7777
}
78-
CliCommand::Serve => {
78+
Command::Serve => {
7979
let mock = MockRelay::run().await?;
8080

8181
println!("Relay running at {}", mock.url());
@@ -115,15 +115,15 @@ async fn run() -> Result<()> {
115115
}
116116
}
117117

118-
async fn handle_command(command: Command, client: &Client) -> Result<()> {
118+
async fn handle_command(command: ShellCommand, client: &Client) -> Result<()> {
119119
match command {
120-
Command::Generate => {
120+
ShellCommand::Generate => {
121121
let keys: Keys = Keys::generate();
122122
println!("Secret key: {}", keys.secret_key().to_bech32()?);
123123
println!("Public key: {}", keys.public_key().to_bech32()?);
124124
Ok(())
125125
}
126-
Command::Sync {
126+
ShellCommand::Sync {
127127
public_key,
128128
relays,
129129
direction,
@@ -179,7 +179,7 @@ async fn handle_command(command: Command, client: &Client) -> Result<()> {
179179

180180
Ok(())
181181
}
182-
Command::Query {
182+
ShellCommand::Query {
183183
id,
184184
author,
185185
kind,
@@ -255,8 +255,8 @@ async fn handle_command(command: Command, client: &Client) -> Result<()> {
255255

256256
Ok(())
257257
}
258-
Command::Database { command } => match command {
259-
DatabaseCommand::Populate { path } => {
258+
ShellCommand::Database { command } => match command {
259+
ShellCommandDatabase::Populate { path } => {
260260
if path.exists() && path.is_file() {
261261
// Open JSON file
262262
let file = File::open(path)?;
@@ -299,13 +299,12 @@ async fn handle_command(command: Command, client: &Client) -> Result<()> {
299299

300300
Ok(())
301301
}
302-
DatabaseCommand::Stats => {
302+
ShellCommandDatabase::Stats => {
303303
println!("TODO");
304304
Ok(())
305305
}
306306
},
307-
Command::Dev {} => Ok(()),
308-
Command::Exit => std::process::exit(0x01),
307+
ShellCommand::Exit => std::process::exit(0x01),
309308
}
310309
}
311310

0 commit comments

Comments
 (0)