Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
cli: Move node addresses command
Browse files Browse the repository at this point in the history
To make things a little more consistent, move the `rad self --address`
command to `rad node config --addresses`, since it's more about
externally-facing configuration of the node, rather than your local user
or profile.
  • Loading branch information
cloudhead committed Feb 26, 2024
1 parent 091f7b7 commit a48081f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
6 changes: 6 additions & 0 deletions radicle-cli/examples/rad-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ $ rad node status
✓ Node is running and listening on [..].
```

```
$ rad node config --addresses
[email protected]:8776
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@seed.cloudhead.io:8776
```

The node also allows us to query data that it has access to such as
the follow policies and the routing table. Before we explore
those commands we'll first follow a peer so that we have something to
Expand Down
5 changes: 0 additions & 5 deletions radicle-cli/examples/rad-self.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,3 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
$ rad self --home
[..]/home/alice/.radicle
```

```
$ rad self --address
[email protected]:8776
```
25 changes: 21 additions & 4 deletions radicle-cli/src/commands/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::time;

use anyhow::anyhow;

use radicle::node::config::ConnectAddress;
use radicle::node::Handle as _;
use radicle::node::{Address, Node, NodeId, PeerAddr};
use radicle::prelude::RepoId;

Expand Down Expand Up @@ -32,7 +34,7 @@ Usage
rad node connect <nid>@<addr> [<option>...]
rad node routing [--rid <rid>] [--nid <nid>] [--json] [<option>...]
rad node events [--timeout <secs>] [-n <count>] [<option>...]
rad node config
rad node config [--addresses]
For `<node-option>` see `radicle-node --help`.
Expand Down Expand Up @@ -68,7 +70,9 @@ pub enum Operation {
addr: PeerAddr<NodeId, Address>,
timeout: time::Duration,
},
Config,
Config {
addresses: bool,
},
Events {
timeout: time::Duration,
count: usize,
Expand Down Expand Up @@ -121,6 +125,7 @@ impl Args for Options {
let mut lines: usize = 60;
let mut count: usize = usize::MAX;
let mut timeout = time::Duration::MAX;
let mut addresses = false;
let mut path = None;
let mut verbose = false;

Expand Down Expand Up @@ -167,6 +172,9 @@ impl Args for Options {
Long("foreground") if matches!(op, Some(OperationName::Start)) => {
foreground = true;
}
Long("addresses") if matches!(op, Some(OperationName::Config)) => {
addresses = true;
}
Long("verbose") | Short('v') if matches!(op, Some(OperationName::Start)) => {
verbose = true;
}
Expand All @@ -191,7 +199,7 @@ impl Args for Options {
})?,
timeout,
},
OperationName::Config => Operation::Config,
OperationName::Config => Operation::Config { addresses },
OperationName::Events => Operation::Events { timeout, count },
OperationName::Routing => Operation::Routing { rid, nid, json },
OperationName::Logs => Operation::Logs { lines },
Expand All @@ -217,7 +225,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
Operation::Connect { addr, timeout } => {
control::connect(&mut node, addr.id, addr.addr, timeout)?
}
Operation::Config => control::config(&node)?,
Operation::Config { addresses } => {
if addresses {
let cfg = node.config()?;
for addr in cfg.external_addresses {
term::print(ConnectAddress::from((*profile.id(), addr)).to_string());
}
} else {
control::config(&node)?;
}
}
Operation::Sessions => {
let sessions = control::sessions(&node)?;
if let Some(table) = sessions {
Expand Down
12 changes: 0 additions & 12 deletions radicle-cli/src/commands/self.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ffi::OsString;

use radicle::crypto::ssh;
use radicle::node::config::ConnectAddress;
use radicle::Profile;

use crate::terminal as term;
Expand All @@ -22,7 +21,6 @@ Options
--did Show your DID
--alias Show your Node alias
--nid Show your Node ID (NID)
--address Show your Node address(es)
--home Show your Radicle home
--config Show the location of your configuration file
--ssh-key Show your public key in OpenSSH format
Expand All @@ -34,7 +32,6 @@ Options
#[derive(Debug)]
enum Show {
Alias,
Address,
NodeId,
Did,
Home,
Expand All @@ -61,9 +58,6 @@ impl Args for Options {
Long("alias") if show.is_none() => {
show = Some(Show::Alias);
}
Long("address") if show.is_none() => {
show = Some(Show::Address);
}
Long("nid") if show.is_none() => {
show = Some(Show::NodeId);
}
Expand Down Expand Up @@ -105,12 +99,6 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
Show::Alias => {
term::print(profile.config.alias());
}
Show::Address => {
let nid = profile.public_key;
for addr in profile.config.node.external_addresses {
term::print(ConnectAddress::from((nid, addr)).to_string());
}
}
Show::NodeId => {
term::print(profile.id());
}
Expand Down
12 changes: 9 additions & 3 deletions radicle-cli/tests/commands.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::Path;
use std::str::FromStr;
use std::{env, thread, time};
use std::{env, net, thread, time};

use radicle::git;
use radicle::node;
use radicle::node::address::Store as _;
use radicle::node::config::seeds::{RADICLE_COMMUNITY_NODE, RADICLE_TEAM_NODE};
use radicle::node::routing::Store as _;
use radicle::node::Handle as _;
use radicle::node::{Alias, DEFAULT_TIMEOUT};
use radicle::node::{Address, Alias, DEFAULT_TIMEOUT};
use radicle::prelude::RepoId;
use radicle::profile;
use radicle::profile::Home;
Expand Down Expand Up @@ -582,7 +582,13 @@ fn rad_node_connect() {
#[test]
fn rad_node() {
let mut environment = Environment::new();
let alice = environment.node(Config::test(Alias::new("alice")));
let alice = environment.node(Config {
external_addresses: vec![
Address::from(net::SocketAddr::from(([41, 12, 98, 112], 8776))),
Address::from_str("seed.cloudhead.io:8776").unwrap(),
],
..Config::test(Alias::new("alice"))
});
let working = tempfile::tempdir().unwrap();
let alice = alice.spawn();

Expand Down

0 comments on commit a48081f

Please sign in to comment.