Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented list function for plugins #762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ninaagrawal
Copy link

first implementation of the list function for plugins

@ninaagrawal ninaagrawal force-pushed the ninaagrawal/plugins branch 2 times, most recently from 1f1eb48 to f43c75c Compare January 10, 2025 19:57
@ninaagrawal ninaagrawal requested review from patrickjcasey and j-lanson and removed request for patrickjcasey January 10, 2025 20:42
#[derive(Debug, Clone)]
pub enum PluginCacheSort {
Oldest,
Alpha,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we also want a sort for highest-to-lowest version numbers

HcPluginCacheIterator{
wd: Box::new(
WalkDir::new(path) //builds a new iterator using WalkDir
.min_depth(3) //makes sure to get the publisher, name, and version folders
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably want to add .max_depth(4) so we only get exactly the plugin dirs.

Copy link
Author

Choose a reason for hiding this comment

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

what about max_depth(3)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

good point, that should work. We just want to make it so only Paths exactly 3 subdirs down are returned.

Comment on lines +3 to +17
use std::path::{Path, PathBuf, Component};
use std::{borrow::Borrow,
time::{SystemTime,Duration},
env
};
use pathbuf::pathbuf;
use tabled::{Table, Tabled};
use walkdir::{DirEntry, WalkDir};
use crate::plugin::PluginId;
use crate::StdResult;
//use super::super::cli::CliConfig;
use crate::error::Result;
use regex::Regex; //used for regex
use semver::{Version, VersionReq};
use crate::cache::repo;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please organize the std and crate imports into 2 single use statements like in repo.rs

)
}
}
fn path_to_plugin_entry(&self, path: &Path) -> Result<PluginCacheEntry> { //does function need to work when you clone a repo?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete comment here

let components: Vec<String> = path
.components()
.filter_map(|component| {
if let Component::Normal(name) = component { //extracts components seperated by "/" from the path
Copy link
Collaborator

Choose a reason for hiding this comment

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

seperated --> separated

Copy link
Author

Choose a reason for hiding this comment

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

Looks like my spelling isn't as good as I thought :)

Copy link
Collaborator

@j-lanson j-lanson left a comment

Choose a reason for hiding this comment

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

I appreciate the thorough testing Nino. I'm requesting some changes for clarity and code hygiene, but overall it is looking good.

Comment on lines +105 to +113
Ok(PluginCacheEntry{
publisher:plugin_publisher,
name:plugin_name,
version: plugin_version,
modified: last_modified
})

}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Some of this formatting seems a bit weird, can you make sure to run cargo fmt locally to run through the Rust formatter?

Comment on lines +124 to +129
if let Ok(ce) = self.path_to_plugin_entry(e.path()) {
Some(ce)
}
else {
None
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this if else structure can be replaced with doing .ok() on the output of self.path_to_plugin_entry(e.path()), which does the same thing. Turns Result<T> into Option<T>, discarding error. Same with the enclosing if else.

Comment on lines +141 to +142
pub path: PathBuf, //path to the root of the plugin cache
pub entries: Vec<PluginCacheEntry>, //needs to store a vector of PluginEntries
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of making fields these pub, I would make a special constructor for HcPluginCache marked with #[cfg(test)] so you can only create it that way in the testing code.


///lists all the plugin entries. Works the same as the function in repo.rs except for
///user can filter plugins by version and publisher
/// TODO: split into inner function that you can call, outer function can call inner and display on the result
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO comment can be removed now

Comment on lines +303 to +306
let results = HcPluginCache::list_inner(entries, time_sort, None, None, None);
let expected_output = vec!["affiliation", "activity", "bugs bunny", "difference"];
let mut actual_output: Vec<&String> = Vec::new();
match results {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of doing match results {}, you can just do list_inner(...).unwrap() on line 303 to deal with the error case. We don't care if test cases panic, because it is treated as a test failure.

Also, to create actual_output you can do something like results.map(|x| &x.name) instead of your for-loop. Should cut down a lot on code lines. Don't forget to propagate these changes to the other tests below.

@@ -64,7 +64,7 @@ impl RepoCacheEntry {
.unwrap_or("<DISPLAY_ERROR>".to_owned())
.to_string()
}
fn display_modified(&self) -> String {
pub fn display_modified(&self) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this likely doesn't need to be pub anymore because you copied the implementation wholesale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants