Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions command-signatures/src/generators/conda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub fn generator() -> CommandSignatureGenerators {
"get_installed_packages",
Generator::script(CommandBuilder::single_command("conda list"), |output| {
output
.trim()
.split('\n')
.skip(2)
.map(Suggestion::new)
.lines()
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.filter_map(|line| line.split_whitespace().next().map(Suggestion::new))
.collect_unordered_results()
}),
)
Expand Down Expand Up @@ -41,3 +41,28 @@ pub fn generator() -> CommandSignatureGenerators {
),
)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_get_installed_packages_post_process() {
let gen = generator();
let generator = gen
.generators()
.iter()
.find(|(name, _)| name.0 == "get_installed_packages")
.unwrap()
.1;

let output = "# packages in environment at /opt/conda:\n#\n# Name Version Build Channel\n\nnumpy 1.26.4 py311h64a7726_0 conda-forge\npip 24.0 pyhd8ed1ab_0 conda-forge\n python 3.11.9 h955ad1f_0\n";
let results = generator.on_complete(output);
let names: Vec<_> = results
.suggestions
.iter()
.map(|s| s.exact_string.as_str())
.collect();
assert_eq!(names, vec!["numpy", "pip", "python"]);
}
}