Skip to content

Commit

Permalink
Plugin and registry now print architecture, added flag to ignore arch…
Browse files Browse the repository at this point in the history
…itecture when searching through registry
  • Loading branch information
ko1N committed Mar 28, 2024
1 parent c771dfd commit ff3d19c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod registry;
#[inline]
fn print_plugin_versions_header() {
println!(
"{0: <16} {1: <16} {2: <16} {3: <8} {4: <65} {5:}",
"NAME", "VERSION", "PLUGIN_VERSION", "DIGEST", "DIGEST_LONG", "CREATED"
"{0: <16} {1: <16} {2: <12} {3: <4} {4: <8} {5: <65} {6:}",
"NAME", "VERSION", "ARCH", "ABI", "DIGEST", "DIGEST_LONG", "CREATED"
);
}
7 changes: 6 additions & 1 deletion src/commands/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ async fn list_local_plugins(plugin_name: Option<&str>) -> Result<()> {
}

println!(
"{0: <16} {1: <16} {2: <16} {3: <8} {4: <65} {5:}",
"{0: <16} {1: <16} {2: <12} {3: <4} {4: <8} {5: <65} {6:}",
variant.descriptor.name,
variant.descriptor.version,
format!(
"{:?}/{:?}",
variant.descriptor.file_type, variant.descriptor.architecture
)
.to_ascii_lowercase(),
variant.descriptor.plugin_version,
&variant.digest[..7],
variant.digest,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn pull(
registry.unwrap_or(MEMFLOW_DEFAULT_REGISTRY),
"latest",
)?;
let variant = memflow_registry_client::find_by_uri(&plugin_uri, None).await?;
let variant = memflow_registry_client::find_by_uri(&plugin_uri, false, None).await?;

// check if file already exists
let file_name = util::plugin_file_name(&variant);
Expand Down
3 changes: 2 additions & 1 deletion src/commands/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
)
.await?;
}
Err(_) => {
Err(err) => {
println!(
"{} Plugin `{}` not found",
console::style("[X]").bold().dim().red(),
plugin_uri
);
return Err(err);
}
}
}
Expand Down
44 changes: 33 additions & 11 deletions src/commands/registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Clap subcommand to query the registry
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};

use crate::error::Result;

Expand All @@ -20,6 +20,18 @@ pub fn metadata() -> Command {
.long("versions")
.help("show the long listing, with each version of each plugin on its own line")
.action(ArgAction::SetTrue),
Arg::new("all-archs")
.short('a')
.long("all-archs")
.alias("all-architectures")
.help("shows plugins regardless of the current architecture")
.action(ArgAction::SetTrue),
Arg::new("limit")
.long("limit")
.value_parser(value_parser!(usize))
.default_value("25")
.help("the amount of plugins to show in the listing")
.action(ArgAction::Set),
]),
Command::new("remove").alias("rm").args([
Arg::new("plugin_digest")
Expand Down Expand Up @@ -51,9 +63,12 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
// TODO: allow changing to another registry provider
match matches.subcommand() {
Some(("list", matches)) => {
let all_archs = matches.get_flag("all-archs");

if let Some(plugin_name) = matches.get_one::<String>("plugin_name") {
let limit = matches.get_one::<usize>("limit").unwrap();
super::print_plugin_versions_header();
list_plugin_versions(registry, plugin_name, 50).await?;
list_plugin_versions(registry, plugin_name, all_archs, *limit).await?;
} else {
let versions = matches.get_flag("versions");

Expand All @@ -63,7 +78,7 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
// TODO: display plugins that do not have a version for our current os?
super::print_plugin_versions_header();
for plugin in plugins.iter() {
list_plugin_versions(registry, &plugin.name, 1).await?;
list_plugin_versions(registry, &plugin.name, all_archs, 1).await?;
}
} else {
println!("{0: <16} DESCRIPTION", "NAME");
Expand Down Expand Up @@ -102,22 +117,29 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
async fn list_plugin_versions(
registry: Option<&str>,
plugin_name: &str,
all_archs: bool,
limit: usize,
) -> Result<()> {
// list versions of a specific plugin
let plugins =
memflow_registry_client::plugin_versions(registry, plugin_name, None, limit).await?;
memflow_registry_client::plugin_versions(registry, plugin_name, all_archs, None, limit)
.await?;
// TODO: dedup versions

for plugin in plugins.iter() {
for variant in plugins.iter() {
println!(
"{0: <16} {1: <16} {2: <16} {3: <8} {4: <65} {5:}",
"{0: <16} {1: <16} {2: <12} {3: <4} {4: <8} {5: <65} {6:}",
plugin_name,
plugin.descriptor.version,
plugin.descriptor.plugin_version,
&plugin.digest[..7],
plugin.digest,
plugin.created_at,
variant.descriptor.version,
format!(
"{:?}/{:?}",
variant.descriptor.file_type, variant.descriptor.architecture
)
.to_ascii_lowercase(),
variant.descriptor.plugin_version,
&variant.digest[..7],
variant.digest,
variant.created_at,
);
}

Expand Down

0 comments on commit ff3d19c

Please sign in to comment.