Skip to content

Conversation

kim
Copy link
Contributor

@kim kim commented Oct 2, 2025

WIP

Comment on lines 78 to 99
pub fn print_database_tree_info(&self, mut out: impl io::Write) -> anyhow::Result<()> {
let fmt_names = |names: &BTreeSet<String>| match names.len() {
0 => <_>::default(),
1 => format!(": {}", names.first().unwrap()),
_ => format!(": {names:?}"),
};

let tree_info = &self.database_tree;

write!(out, "{}{}", tree_info.root.identity, fmt_names(&tree_info.root.names))?;
for (identity, info) in &tree_info.children {
let names = fmt_names(&info.names);
let parent = info
.parent
.map(|parent| format!(" (parent: {parent})"))
.unwrap_or_default();

write!(out, "{identity}{parent}{names}")?;
}

Ok(())
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aasoni I have been a little un-imaginative about how to render the tree of children when trying to delete a parent. Note also that a database can have more than one name.

If you have a specific idea of how this should be rendered, please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe @bfops ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just getting to this. I think it's fine to do "something" and improve it later if we feel strongly about it. This isn't a very common subcommand in people's workflows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed this to render a tree (like the tree command), unless --yes is given:

0000000000000000000000000000000000000000000000000000000000000001: parent
├── 0000000000000000000000000000000000000000000000000000000000000004: bro, sibling
└── 0000000000000000000000000000000000000000000000000000000000000002: child
    ├── 0000000000000000000000000000000000000000000000000000000000000005
    └── 0000000000000000000000000000000000000000000000000000000000000003: grandchild

We could abbreviate the identities if, and only if, there are no collisions. I'll leave that as a future exercise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants