cli: Add `rad self --address` command
Useful when running seed nodes.
This commit is contained in:
parent
131103cb53
commit
c13c658f4e
|
|
@ -38,3 +38,8 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
|
||||||
$ rad self --home
|
$ rad self --home
|
||||||
[..]/home/alice/.radicle
|
[..]/home/alice/.radicle
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rad self --address
|
||||||
|
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi@seed.alice.acme:8776
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
|
||||||
use radicle::crypto::ssh;
|
use radicle::crypto::ssh;
|
||||||
|
use radicle::node::config::ConnectAddress;
|
||||||
use radicle::Profile;
|
use radicle::Profile;
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
|
@ -18,9 +19,10 @@ Usage
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
|
||||||
|
--did Show your DID
|
||||||
--alias Show your Node alias
|
--alias Show your Node alias
|
||||||
--nid Show your Node ID (NID)
|
--nid Show your Node ID (NID)
|
||||||
--did Show your DID
|
--address Show your Node address(es)
|
||||||
--home Show your Radicle home
|
--home Show your Radicle home
|
||||||
--config Show the location of your configuration file
|
--config Show the location of your configuration file
|
||||||
--ssh-key Show your public key in OpenSSH format
|
--ssh-key Show your public key in OpenSSH format
|
||||||
|
|
@ -32,6 +34,7 @@ Options
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Show {
|
enum Show {
|
||||||
Alias,
|
Alias,
|
||||||
|
Address,
|
||||||
NodeId,
|
NodeId,
|
||||||
Did,
|
Did,
|
||||||
Home,
|
Home,
|
||||||
|
|
@ -58,6 +61,9 @@ impl Args for Options {
|
||||||
Long("alias") if show.is_none() => {
|
Long("alias") if show.is_none() => {
|
||||||
show = Some(Show::Alias);
|
show = Some(Show::Alias);
|
||||||
}
|
}
|
||||||
|
Long("address") if show.is_none() => {
|
||||||
|
show = Some(Show::Address);
|
||||||
|
}
|
||||||
Long("nid") if show.is_none() => {
|
Long("nid") if show.is_none() => {
|
||||||
show = Some(Show::NodeId);
|
show = Some(Show::NodeId);
|
||||||
}
|
}
|
||||||
|
|
@ -99,6 +105,12 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
Show::Alias => {
|
Show::Alias => {
|
||||||
term::print(profile.config.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 => {
|
Show::NodeId => {
|
||||||
term::print(profile.id());
|
term::print(profile.id());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1161,7 +1161,10 @@ fn rad_sync_without_node() {
|
||||||
#[test]
|
#[test]
|
||||||
fn rad_self() {
|
fn rad_self() {
|
||||||
let mut environment = Environment::new();
|
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");
|
let working = environment.tmp().join("working");
|
||||||
|
|
||||||
test("examples/rad-self.md", working, Some(&alice.home), []).unwrap();
|
test("examples/rad-self.md", working, Some(&alice.home), []).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue