Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Flesh out `rad self`
Alexis Sellier committed 3 years ago
commit 13998dcf46026c31a8eaff1c2b52089d28644a3b
parent fdd6bca31118ea0a40675890c06c047333ab2ac1
4 files changed +72 -8
modified 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
added 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
+
```
modified 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(),
    ]);

modified radicle-cli/tests/commands.rs
@@ -322,6 +322,15 @@ fn rad_clone() {
}

#[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);