Skip to content

Commit

Permalink
Merge pull request #2821 from ThorstenHans/feature/plugins-inspect
Browse files Browse the repository at this point in the history
Adding the `spin plugins inspect` command
  • Loading branch information
itowlson committed Sep 15, 2024
2 parents 6f010fa + 0a65d14 commit 4fbf872
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/commands/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub enum PluginCommands {

/// Fetch the latest Spin plugins from the spin-plugins repository.
Update,

/// Print information about a plugin.
Show(Show),
}

impl PluginCommands {
Expand All @@ -50,6 +53,7 @@ impl PluginCommands {
PluginCommands::Uninstall(cmd) => cmd.run().await,
PluginCommands::Upgrade(cmd) => cmd.run().await,
PluginCommands::Update => update().await,
PluginCommands::Show(cmd) => cmd.run().await,
}
}
}
Expand Down Expand Up @@ -416,6 +420,38 @@ impl Upgrade {
}
}

#[derive(Parser, Debug)]
pub struct Show {
/// Name of Spin plugin.
pub name: String,
}

impl Show {
pub async fn run(self) -> Result<()> {
let manager = PluginManager::try_default()?;
let manifest = manager
.get_manifest(
&ManifestLocation::PluginsRepository(PluginLookup::new(&self.name, None)),
false,
SPIN_VERSION,
)
.await?;

println!(
"{}: {} (License: {})\n{}\n{}",
manifest.name(),
manifest.version(),
manifest.license(),
manifest
.homepage_url()
.map(|u| format!("{u}\n"))
.unwrap_or_default(),
manifest.description().unwrap_or("No description provided"),
);
Ok(())
}
}

fn is_potential_upgrade(current: &PluginManifest, candidate: &PluginManifest) -> bool {
match (current.try_version(), candidate.try_version()) {
(Ok(cur_ver), Ok(cand_ver)) => cand_ver > cur_ver,
Expand Down

0 comments on commit 4fbf872

Please sign in to comment.