Skip to content

Commit

Permalink
Make sure that list of plugins is sorted and unique
Browse files Browse the repository at this point in the history
The sorting is performed by the file_name instead of the full text to be
printed or full path
  • Loading branch information
crodas committed Dec 15, 2023
1 parent d95e313 commit 401f029
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions forc/src/cli/commands/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,32 @@ pub struct Command {
describe: bool,
}

fn get_file_name(path: &Path) -> String {
path.file_name()
.expect("Failed to read file name")
.to_str()
.expect("Failed to print file name")
.to_string()
}

pub(crate) fn exec(command: PluginsCommand) -> ForcResult<()> {
let PluginsCommand {
print_full_path,
describe,
} = command;

let mut plugins = crate::cli::plugin::find_all()
.map(|path| {
print_plugin(path.clone(), print_full_path, describe)
.map(|info| (get_file_name(&path), info))
})
.collect::<Result<Vec<_>, _>>()?;
plugins.sort_by(|a, b| a.0.cmp(&b.0));
plugins.dedup_by(|a, b| a.0 == b.0);

info!("Installed Plugins:");
for path in crate::cli::plugin::find_all() {
info!("{}", print_plugin(path, print_full_path, describe)?);
for plugin in plugins {
info!("{}", plugin.1);
}
Ok(())
}
Expand Down Expand Up @@ -72,11 +89,7 @@ fn format_print_description(
let display = if print_full_path {
path.display().to_string()
} else {
path.file_name()
.expect("Failed to read file name")
.to_str()
.expect("Failed to print file name")
.to_string()
get_file_name(&path)
};

let description = parse_description_for_plugin(&path);
Expand Down

0 comments on commit 401f029

Please sign in to comment.