Skip to content

Commit 33130a4

Browse files
authored
Merge pull request #2412 from itowlson/plugin-prompt-shenanigans
Rationalise plugin install prompts
2 parents a072c1f + 0e11faf commit 33130a4

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

src/commands/external.rs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,45 @@ async fn consider_install(
158158
}
159159
plugin_installer.run().await?;
160160
}
161-
Ok(None) // No update badgering needed if we just updated/installed it!
162-
} else if stderr().is_terminal() && matches_catalogue_plugin(plugin_store, plugin_name) {
163-
if offer_install(plugin_name)? {
164-
let plugin_installer = installer_for(plugin_name);
165-
plugin_installer.run().await?;
166-
eprintln!();
167-
Ok(None) // No update badgering needed if we just updated/installed it!
168-
} else {
169-
process::exit(2);
161+
return Ok(None); // No update badgering needed if we just updated/installed it!
162+
}
163+
164+
if stderr().is_terminal() {
165+
if let Some(plugin) = match_catalogue_plugin(plugin_store, plugin_name) {
166+
let package = spin_plugins::manager::get_package(&plugin)?;
167+
if offer_install(&plugin, package)? {
168+
let plugin_installer = installer_for(plugin_name);
169+
plugin_installer.run().await?;
170+
eprintln!();
171+
return Ok(None); // No update badgering needed if we just updated/installed it!
172+
} else {
173+
process::exit(2);
174+
}
170175
}
171-
} else {
172-
tracing::debug!("Tried to resolve {plugin_name} to plugin, got {e}");
173-
terminal::error!("'{plugin_name}' is not a known Spin command. See spin --help.\n");
174-
print_similar_commands(app, plugin_name);
175-
process::exit(2);
176176
}
177+
178+
tracing::debug!("Tried to resolve {plugin_name} to plugin, got {e}");
179+
terminal::error!("'{plugin_name}' is not a known Spin command. See spin --help.\n");
180+
print_similar_commands(app, plugin_name);
181+
process::exit(2);
177182
}
178183

179-
fn offer_install(name: &str) -> anyhow::Result<bool, anyhow::Error> {
180-
terminal::warn!("`{name}` is not a known Spin command, but there is a plugin with that name.");
184+
fn offer_install(
185+
plugin: &spin_plugins::manifest::PluginManifest,
186+
package: &spin_plugins::manifest::PluginPackage,
187+
) -> anyhow::Result<bool, anyhow::Error> {
188+
terminal::warn!(
189+
"`{}` is not a known Spin command, but there is a plugin with that name.",
190+
plugin.name()
191+
);
192+
eprintln!(
193+
"The plugin has the {} license and would download from {}",
194+
plugin.license(),
195+
package.url()
196+
);
181197
let choice = dialoguer::Confirm::new()
182-
.with_prompt("Would you like to install and run it now?")
198+
.with_prompt("Would you like to install this plugin and run it now?")
199+
.default(false)
183200
.interact_opt()?
184201
.unwrap_or(false);
185202
Ok(choice)
@@ -196,13 +213,16 @@ fn installer_for(plugin_name: &str) -> Install {
196213
}
197214
}
198215

199-
fn matches_catalogue_plugin(plugin_store: &PluginStore, plugin_name: &str) -> bool {
216+
fn match_catalogue_plugin(
217+
plugin_store: &PluginStore,
218+
plugin_name: &str,
219+
) -> Option<spin_plugins::manifest::PluginManifest> {
200220
let Ok(known) = plugin_store.catalogue_manifests() else {
201-
return false;
221+
return None;
202222
};
203223
known
204-
.iter()
205-
.any(|m| m.name() == plugin_name && m.has_compatible_package())
224+
.into_iter()
225+
.find(|m| m.name() == plugin_name && m.has_compatible_package())
206226
}
207227

208228
async fn report_badger_result(badger: tokio::task::JoinHandle<BadgerChecker>) {

src/commands/plugins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ fn prompt_confirm_install(manifest: &PluginManifest, package: &PluginPackage) ->
653653
let prompt = "Are you sure you want to continue?".to_string();
654654
let install = dialoguer::Confirm::new()
655655
.with_prompt(prompt)
656-
.default(false)
656+
.default(true)
657657
.interact_opt()?
658658
.unwrap_or(false);
659659
if !install {

0 commit comments

Comments
 (0)