cli: Add `rad self --address` command

Useful when running seed nodes.
This commit is contained in:
cloudhead 2024-01-25 21:16:58 +01:00
parent 131103cb53
commit c13c658f4e
No known key found for this signature in database
3 changed files with 22 additions and 2 deletions

View File

@ -38,3 +38,8 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
$ rad self --home
[..]/home/alice/.radicle
```
```
$ rad self --address
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@seed.alice.acme:8776
```

View File

@ -1,6 +1,7 @@
use std::ffi::OsString;
use radicle::crypto::ssh;
use radicle::node::config::ConnectAddress;
use radicle::Profile;
use crate::terminal as term;
@ -18,9 +19,10 @@ Usage
Options
--did Show your DID
--alias Show your Node alias
--nid Show your Node ID (NID)
--did Show your DID
--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
@ -32,6 +34,7 @@ Options
#[derive(Debug)]
enum Show {
Alias,
Address,
NodeId,
Did,
Home,
@ -58,6 +61,9 @@ 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);
}
@ -99,6 +105,12 @@ 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());
}

View File

@ -1161,7 +1161,10 @@ fn rad_sync_without_node() {
#[test]
fn rad_self() {
let mut environment = Environment::new();
let alice = environment.node(Config::test(Alias::new("alice")));
let alice = environment.node(Config {
external_addresses: vec!["seed.alice.acme:8776".parse().unwrap()],
..Config::test(Alias::new("alice"))
});
let working = environment.tmp().join("working");
test("examples/rad-self.md", working, Some(&alice.home), []).unwrap();