Skip to content

Commit

Permalink
Sort channel list output
Browse files Browse the repository at this point in the history
  • Loading branch information
vihu committed Nov 20, 2023
1 parent 00c63a0 commit aa9bb64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ impl Cmd {
let lookup_tree = db.open_tree("lookup")?;
let channel_tree = db.open_tree("channel")?;

let mut results = vec![];
for entry in lookup_tree.iter() {
let (key, value) = entry?;
let key_str = String::from_utf8(key.to_vec())?;
let channel_name = String::from_utf8(key.to_vec())?;
let channel_index = String::from_utf8(value.to_vec())?;
if let Ok(Some(_channel_url)) = channel_tree.get(&channel_index) {
println!("{} \t {}", channel_index, key_str);
results.push((channel_index.parse::<u32>()?, channel_name));
}
}

results.sort_by(|a, b| a.0.cmp(&b.0));

for (channel_index, channel_name) in results {
println!("{} \t {}", channel_index, channel_name);
}

Ok(())
}
}
6 changes: 3 additions & 3 deletions src/cli/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Cmd {

for entry in lookup_tree.iter() {
let (key, value) = entry?;
let key_str = String::from_utf8(key.to_vec())?;
if key_str.contains(channel_name.trim()) {
let db_channel_name = String::from_utf8(key.to_vec())?;
if db_channel_name.contains(channel_name.trim()) {
let channel_index = String::from_utf8(value.to_vec())?;
if let Ok(Some(_channel_url)) = channel_tree.get(&channel_index) {
println!("{} \t {}", channel_index, key_str);
println!("{} \t {}", channel_index, db_channel_name);
}
}
}
Expand Down

0 comments on commit aa9bb64

Please sign in to comment.