radicle: make alias optional
Previously the alias field was simply a string which could possibly be empty. Some checks were made to see if this string was empty. Instead, make the logic more obvious by making the alias field optional. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
0302701c98
commit
39be7db1e9
|
|
@ -36,10 +36,9 @@ fn print_nodes(node: &Node) -> anyhow::Result<()> {
|
||||||
for tracking::Node { id, alias, policy } in node.tracked_nodes()? {
|
for tracking::Node { id, alias, policy } in node.tracked_nodes()? {
|
||||||
t.push([
|
t.push([
|
||||||
term::format::highlight(Did::from(id).to_string()),
|
term::format::highlight(Did::from(id).to_string()),
|
||||||
if alias.is_empty() {
|
match alias {
|
||||||
term::format::secondary("n/a".to_string())
|
None => term::format::secondary("n/a".to_string()),
|
||||||
} else {
|
Some(alias) => term::format::secondary(alias),
|
||||||
term::format::secondary(alias)
|
|
||||||
},
|
},
|
||||||
term::format::secondary(policy.to_string()),
|
term::format::secondary(policy.to_string()),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{fmt, io};
|
use std::{fmt, io, ops::Not as _};
|
||||||
|
|
||||||
use sqlite as sql;
|
use sqlite as sql;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -159,15 +159,10 @@ impl Config {
|
||||||
|
|
||||||
if let Some(Ok(row)) = stmt.into_iter().next() {
|
if let Some(Ok(row)) = stmt.into_iter().next() {
|
||||||
let alias = row.read::<&str, _>("alias");
|
let alias = row.read::<&str, _>("alias");
|
||||||
|
let alias = alias.is_empty().not().then_some(alias.to_owned());
|
||||||
|
let policy = row.read::<Policy, _>("policy");
|
||||||
|
|
||||||
return Ok(Some((
|
return Ok(Some((alias, policy)));
|
||||||
if alias.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(alias.to_owned())
|
|
||||||
},
|
|
||||||
row.read::<Policy, _>("policy"),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
@ -200,6 +195,7 @@ impl Config {
|
||||||
while let Some(Ok(row)) = stmt.next() {
|
while let Some(Ok(row)) = stmt.next() {
|
||||||
let id = row.read("id");
|
let id = row.read("id");
|
||||||
let alias = row.read::<&str, _>("alias").to_owned();
|
let alias = row.read::<&str, _>("alias").to_owned();
|
||||||
|
let alias = alias.is_empty().not().then_some(alias.to_owned());
|
||||||
let policy = row.read::<Policy, _>("policy");
|
let policy = row.read::<Policy, _>("policy");
|
||||||
|
|
||||||
entries.push(Node { id, alias, policy });
|
entries.push(Node { id, alias, policy });
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ impl radicle::node::Handle for Handle {
|
||||||
.copied()
|
.copied()
|
||||||
.map(|id| tracking::Node {
|
.map(|id| tracking::Node {
|
||||||
id,
|
id,
|
||||||
alias: "".to_string(),
|
alias: None,
|
||||||
policy: tracking::Policy::Track,
|
policy: tracking::Policy::Track,
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ pub struct Repo {
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub alias: Alias,
|
pub alias: Option<Alias>,
|
||||||
pub policy: Policy,
|
pub policy: Policy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue