cli: Flesh out `rad self`

This commit is contained in:
Alexis Sellier 2023-03-15 09:59:06 +01:00
parent fdd6bca311
commit 13998dcf46
No known key found for this signature in database
4 changed files with 72 additions and 8 deletions

View File

@ -17,7 +17,7 @@ You can get the above information at all times using the `self` command:
```
$ rad self
ID did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
DID did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
Node ID z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
Key (hash) SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
Key (full) ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1

View File

@ -0,0 +1,31 @@
The `rad self` command is used to display information about your local
device and node.
```
$ rad self
DID did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
Node ID z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
Key (hash) SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
Key (full) ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
Storage (git) [..]
Storage (keys) [..]
Node (socket) [..]
```
If you need to display only your DID, Node ID, or SSH Public Key, you can use
the various options available:
```
$ rad self --did
did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
```
```
$ rad self --nid
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
```
```
$ rad self --ssh-key
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
```

View File

@ -17,14 +17,20 @@ Usage
Options
--id Show ID
--help Show help
--nid Show your Node ID
--did Show your DID
--ssh-key Show your public key in OpenSSH format
--ssh-fingerprint Show your public key fingerprint in OpenSSH format
--help Show help
"#,
};
#[derive(Debug)]
enum Show {
Id,
NodeId,
Did,
SshKey,
SshFingerprint,
All,
}
@ -42,8 +48,17 @@ impl Args for Options {
while let Some(arg) = parser.next()? {
match arg {
Long("id") if show.is_none() => {
show = Some(Show::Id);
Long("nid") if show.is_none() => {
show = Some(Show::NodeId);
}
Long("did") if show.is_none() => {
show = Some(Show::Did);
}
Long("ssh-key") if show.is_none() => {
show = Some(Show::SshKey);
}
Long("ssh-fingerprint") if show.is_none() => {
show = Some(Show::SshFingerprint);
}
Long("help") => {
return Err(Error::Help.into());
@ -65,9 +80,18 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let profile = ctx.profile()?;
match options.show {
Show::Id => {
Show::NodeId => {
term::print(profile.id());
}
Show::Did => {
term::print(profile.did());
}
Show::SshKey => {
term::print(ssh::fmt::key(profile.id()));
}
Show::SshFingerprint => {
term::print(ssh::fmt::fingerprint(profile.id()));
}
Show::All => all(&profile)?,
}
@ -79,7 +103,7 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
let did = profile.did();
table.push([
term::format::style("ID").to_string(),
term::format::style("DID").to_string(),
term::format::tertiary(did).to_string(),
]);

View File

@ -321,6 +321,15 @@ fn rad_clone() {
test("examples/rad-clone.md", working, Some(&bob.home), []).unwrap();
}
#[test]
fn rad_self() {
let mut environment = Environment::new();
let alice = environment.node("alice");
let working = environment.tmp().join("working");
test("examples/rad-self.md", working, Some(&alice.home), []).unwrap();
}
#[test]
fn rad_clone_unknown() {
logger::init(log::Level::Debug);