From da19cb7731ae24f511f266f09a80e0b78acf862f Mon Sep 17 00:00:00 2001 From: Thorsten Hans Date: Thu, 12 Sep 2024 12:56:40 +0200 Subject: [PATCH 1/3] chore(plugins): Add `spin plugins inspect` command Users can print detailed information of a plugin before installing it Signed-off-by: Thorsten Hans --- src/commands/plugins.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/commands/plugins.rs b/src/commands/plugins.rs index 86aa328cd0..e80c9f0e5a 100644 --- a/src/commands/plugins.rs +++ b/src/commands/plugins.rs @@ -39,6 +39,9 @@ pub enum PluginCommands { /// Fetch the latest Spin plugins from the spin-plugins repository. Update, + + /// Print information about a plugin. + Inspect(Inspect), } impl PluginCommands { @@ -50,6 +53,7 @@ impl PluginCommands { PluginCommands::Uninstall(cmd) => cmd.run().await, PluginCommands::Upgrade(cmd) => cmd.run().await, PluginCommands::Update => update().await, + PluginCommands::Inspect(cmd) => cmd.run().await, } } } @@ -416,6 +420,38 @@ impl Upgrade { } } +#[derive(Parser, Debug)] +pub struct Inspect { + /// Name of Spin plugin. + pub name: String, +} + +impl Inspect { + 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\n{}", + manifest.name(), + manifest.version(), + manifest.license(), + manifest + .homepage_url() + .map(|u| u.to_string()) + .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, From cc5796f5894cb52d330fcc868942dae839f00832 Mon Sep 17 00:00:00 2001 From: Thorsten Hans Date: Thu, 12 Sep 2024 13:02:20 +0200 Subject: [PATCH 2/3] chore(plugins): Use colon as separator instead of a comma Signed-off-by: Thorsten Hans --- src/commands/plugins.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/plugins.rs b/src/commands/plugins.rs index e80c9f0e5a..9c185041f7 100644 --- a/src/commands/plugins.rs +++ b/src/commands/plugins.rs @@ -438,7 +438,7 @@ impl Inspect { .await?; println!( - "{}, {} (License: {})\n{}\n\n{}", + "{}: {} (License: {})\n{}\n\n{}", manifest.name(), manifest.version(), manifest.license(), From 0a65d148e4d0c3266ea8e89c8a592613b8c6fc3b Mon Sep 17 00:00:00 2001 From: Thorsten Hans Date: Fri, 13 Sep 2024 10:53:17 +0200 Subject: [PATCH 3/3] chore: rename command to show and fix show-layout Signed-off-by: Thorsten Hans --- src/commands/plugins.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/commands/plugins.rs b/src/commands/plugins.rs index 9c185041f7..fc2385ecf3 100644 --- a/src/commands/plugins.rs +++ b/src/commands/plugins.rs @@ -41,7 +41,7 @@ pub enum PluginCommands { Update, /// Print information about a plugin. - Inspect(Inspect), + Show(Show), } impl PluginCommands { @@ -53,7 +53,7 @@ impl PluginCommands { PluginCommands::Uninstall(cmd) => cmd.run().await, PluginCommands::Upgrade(cmd) => cmd.run().await, PluginCommands::Update => update().await, - PluginCommands::Inspect(cmd) => cmd.run().await, + PluginCommands::Show(cmd) => cmd.run().await, } } } @@ -421,12 +421,12 @@ impl Upgrade { } #[derive(Parser, Debug)] -pub struct Inspect { +pub struct Show { /// Name of Spin plugin. pub name: String, } -impl Inspect { +impl Show { pub async fn run(self) -> Result<()> { let manager = PluginManager::try_default()?; let manifest = manager @@ -438,13 +438,13 @@ impl Inspect { .await?; println!( - "{}: {} (License: {})\n{}\n\n{}", + "{}: {} (License: {})\n{}\n{}", manifest.name(), manifest.version(), manifest.license(), manifest .homepage_url() - .map(|u| u.to_string()) + .map(|u| format!("{u}\n")) .unwrap_or_default(), manifest.description().unwrap_or("No description provided"), );