diff --git a/radicle-cli/examples/rad-auth.md b/radicle-cli/examples/rad-auth.md index e606146f..207f306e 100644 --- a/radicle-cli/examples/rad-auth.md +++ b/radicle-cli/examples/rad-auth.md @@ -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 diff --git a/radicle-cli/examples/rad-self.md b/radicle-cli/examples/rad-self.md new file mode 100644 index 00000000..d5230b40 --- /dev/null +++ b/radicle-cli/examples/rad-self.md @@ -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 +``` diff --git a/radicle-cli/src/commands/self.rs b/radicle-cli/src/commands/self.rs index a466cd51..057c6923 100644 --- a/radicle-cli/src/commands/self.rs +++ b/radicle-cli/src/commands/self.rs @@ -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(), ]); diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index b1d1f168..85679899 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -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);