diff --git a/src/cli/list.rs b/src/cli/list.rs index b2b6d89..2d05533 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -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::()?, 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(()) } } diff --git a/src/cli/search.rs b/src/cli/search.rs index 660c704..36ca3f5 100644 --- a/src/cli/search.rs +++ b/src/cli/search.rs @@ -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); } } }