cli: Make `rad node connect` work like `--connect`
It was using a different syntax.
This commit is contained in:
parent
d6e8f0c53e
commit
f73389fc62
|
|
@ -25,7 +25,7 @@ network. For example, let's connect to a known peer using their Node
|
||||||
ID and their network address:
|
ID and their network address:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad node connect z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk 0.0.0.0:3679
|
$ rad node connect z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk@0.0.0.0:3679
|
||||||
✓ Connecting to z6Mkt67…v4N1tRk@0.0.0.0:3679...
|
✓ Connecting to z6Mkt67…v4N1tRk@0.0.0.0:3679...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::time;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
||||||
use radicle::node::{Address, Node, NodeId, ROUTING_DB_FILE, TRACKING_DB_FILE};
|
use radicle::node::{Address, Node, NodeId, PeerAddr, ROUTING_DB_FILE, TRACKING_DB_FILE};
|
||||||
use radicle::prelude::Id;
|
use radicle::prelude::Id;
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
|
@ -29,7 +29,7 @@ Usage
|
||||||
rad node start [--daemon | -d] [<option>...] [-- <node-option>...]
|
rad node start [--daemon | -d] [<option>...] [-- <node-option>...]
|
||||||
rad node stop [<option>...]
|
rad node stop [<option>...]
|
||||||
rad node logs [-n <lines>]
|
rad node logs [-n <lines>]
|
||||||
rad node connect <nid> <addr> [<option>...]
|
rad node connect <nid>@<addr> [<option>...]
|
||||||
rad node routing [--rid <rid>] [--nid <nid>] [--json] [<option>...]
|
rad node routing [--rid <rid>] [--nid <nid>] [--json] [<option>...]
|
||||||
rad node tracking [--repos | --nodes] [<option>...]
|
rad node tracking [--repos | --nodes] [<option>...]
|
||||||
rad node events [<option>...]
|
rad node events [<option>...]
|
||||||
|
|
@ -59,8 +59,7 @@ pub struct Options {
|
||||||
|
|
||||||
pub enum Operation {
|
pub enum Operation {
|
||||||
Connect {
|
Connect {
|
||||||
nid: NodeId,
|
addr: PeerAddr<NodeId, Address>,
|
||||||
addr: Address,
|
|
||||||
},
|
},
|
||||||
Events,
|
Events,
|
||||||
Routing {
|
Routing {
|
||||||
|
|
@ -114,7 +113,7 @@ impl Args for Options {
|
||||||
let mut nid: Option<NodeId> = None;
|
let mut nid: Option<NodeId> = None;
|
||||||
let mut rid: Option<Id> = None;
|
let mut rid: Option<Id> = None;
|
||||||
let mut json: bool = false;
|
let mut json: bool = false;
|
||||||
let mut addr: Option<Address> = None;
|
let mut addr: Option<PeerAddr<NodeId, Address>> = None;
|
||||||
let mut lines: usize = 10;
|
let mut lines: usize = 10;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
|
|
@ -135,17 +134,7 @@ impl Args for Options {
|
||||||
unknown => anyhow::bail!("unknown operation '{}'", unknown),
|
unknown => anyhow::bail!("unknown operation '{}'", unknown),
|
||||||
},
|
},
|
||||||
Value(val) if matches!(op, Some(OperationName::Connect)) => {
|
Value(val) if matches!(op, Some(OperationName::Connect)) => {
|
||||||
match term::args::nid(&val) {
|
addr = Some(val.parse()?);
|
||||||
Ok(val) => {
|
|
||||||
nid = Some(val);
|
|
||||||
}
|
|
||||||
Err(e1) => match term::args::addr(&val) {
|
|
||||||
Ok(val) => {
|
|
||||||
addr = Some(val);
|
|
||||||
}
|
|
||||||
Err(e2) => return Err(anyhow!("'{}' or '{}'", e1, e2)),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Long("rid") if matches!(op, Some(OperationName::Routing)) => {
|
Long("rid") if matches!(op, Some(OperationName::Routing)) => {
|
||||||
let val = parser.value()?;
|
let val = parser.value()?;
|
||||||
|
|
@ -177,8 +166,9 @@ impl Args for Options {
|
||||||
|
|
||||||
let op = match op.unwrap_or_default() {
|
let op = match op.unwrap_or_default() {
|
||||||
OperationName::Connect => Operation::Connect {
|
OperationName::Connect => Operation::Connect {
|
||||||
nid: nid.ok_or_else(|| anyhow!("an NID must be provided"))?,
|
addr: addr.ok_or_else(|| {
|
||||||
addr: addr.ok_or_else(|| anyhow!("an address must be provided"))?,
|
anyhow!("an address of the form `<nid>@<host>:<port>` must be provided")
|
||||||
|
})?,
|
||||||
},
|
},
|
||||||
OperationName::Events => Operation::Events,
|
OperationName::Events => Operation::Events,
|
||||||
OperationName::Routing => Operation::Routing { rid, nid, json },
|
OperationName::Routing => Operation::Routing { rid, nid, json },
|
||||||
|
|
@ -198,9 +188,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let profile = ctx.profile()?;
|
let profile = ctx.profile()?;
|
||||||
|
|
||||||
match options.op {
|
match options.op {
|
||||||
Operation::Connect { nid, addr } => {
|
Operation::Connect { addr } => {
|
||||||
let mut node = Node::new(profile.socket());
|
let mut node = Node::new(profile.socket());
|
||||||
control::connect(&mut node, nid, addr)?
|
control::connect(&mut node, addr.id, addr.addr)?
|
||||||
}
|
}
|
||||||
Operation::Events => {
|
Operation::Events => {
|
||||||
let node = Node::new(profile.socket());
|
let node = Node::new(profile.socket());
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use crate::crypto::PublicKey;
|
||||||
use crate::identity::Id;
|
use crate::identity::Id;
|
||||||
use crate::storage::RefUpdate;
|
use crate::storage::RefUpdate;
|
||||||
|
|
||||||
|
pub use cyphernet::addr::PeerAddr;
|
||||||
pub use events::{Event, Events};
|
pub use events::{Event, Events};
|
||||||
pub use features::Features;
|
pub use features::Features;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue