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()? {
|
||||
t.push([
|
||||
term::format::highlight(Did::from(id).to_string()),
|
||||
if alias.is_empty() {
|
||||
term::format::secondary("n/a".to_string())
|
||||
} else {
|
||||
term::format::secondary(alias)
|
||||
match alias {
|
||||
None => term::format::secondary("n/a".to_string()),
|
||||
Some(alias) => term::format::secondary(alias),
|
||||
},
|
||||
term::format::secondary(policy.to_string()),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::type_complexity)]
|
||||
use std::path::Path;
|
||||
use std::{fmt, io};
|
||||
use std::{fmt, io, ops::Not as _};
|
||||
|
||||
use sqlite as sql;
|
||||
use thiserror::Error;
|
||||
|
|
@ -159,15 +159,10 @@ impl Config {
|
|||
|
||||
if let Some(Ok(row)) = stmt.into_iter().next() {
|
||||
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((
|
||||
if alias.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(alias.to_owned())
|
||||
},
|
||||
row.read::<Policy, _>("policy"),
|
||||
)));
|
||||
return Ok(Some((alias, policy)));
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
|
@ -200,6 +195,7 @@ impl Config {
|
|||
while let Some(Ok(row)) = stmt.next() {
|
||||
let id = row.read("id");
|
||||
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");
|
||||
|
||||
entries.push(Node { id, alias, policy });
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl radicle::node::Handle for Handle {
|
|||
.copied()
|
||||
.map(|id| tracking::Node {
|
||||
id,
|
||||
alias: "".to_string(),
|
||||
alias: None,
|
||||
policy: tracking::Policy::Track,
|
||||
})
|
||||
.collect())
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub struct Repo {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Node {
|
||||
pub id: NodeId,
|
||||
pub alias: Alias,
|
||||
pub alias: Option<Alias>,
|
||||
pub policy: Policy,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue