diff --git a/radicle-cli/examples/rad-auth-errors.md b/radicle-cli/examples/rad-auth-errors.md new file mode 100644 index 00000000..c723dec1 --- /dev/null +++ b/radicle-cli/examples/rad-auth-errors.md @@ -0,0 +1,17 @@ +Note that aliases must not be longer than 32 bytes, or you will get an error. +There are other rules as well: + +``` (fail) +$ rad auth --alias "5fad63fe6b339fa92c588d926121bea6240773a7" +✗ Error: rad auth: alias cannot be greater than 32 bytes +``` + +``` (fail) +$ rad auth --alias "john doe" +✗ Error: rad auth: alias cannot contain whitespace or control characters +``` + +``` (fail) +$ rad auth --alias "" +✗ Error: rad auth: alias cannot be empty +``` diff --git a/radicle-cli/examples/rad-auth.md b/radicle-cli/examples/rad-auth.md index dd657c14..8dc0e588 100644 --- a/radicle-cli/examples/rad-auth.md +++ b/radicle-cli/examples/rad-auth.md @@ -25,6 +25,7 @@ did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi ``` You can also show your alias: + ``` $ rad self --alias alice diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index 80bb85f3..246d0286 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -128,6 +128,11 @@ fn rad_auth() { test("examples/rad-auth.md", Path::new("."), None, []).unwrap(); } +#[test] +fn rad_auth_errors() { + test("examples/rad-auth-errors.md", Path::new("."), None, []).unwrap(); +} + #[test] fn rad_issue() { let mut environment = Environment::new(); diff --git a/radicle/src/node.rs b/radicle/src/node.rs index a018cd0f..7b0e15f3 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -206,6 +206,7 @@ impl PartialOrd for SyncStatus { /// Node alias. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, serde::Serialize, serde::Deserialize)] +#[serde(try_from = "String", into = "String")] pub struct Alias(String); impl Alias { @@ -288,6 +289,14 @@ impl FromStr for Alias { } } +impl TryFrom for Alias { + type Error = AliasError; + + fn try_from(value: String) -> Result { + Alias::from_str(&value) + } +} + /// Options passed to the "connect" node command. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ConnectOptions {