@@ -158,28 +158,45 @@ async fn consider_install(
158
158
}
159
159
plugin_installer. run ( ) . await ?;
160
160
}
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
+ }
170
175
}
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 ) ;
176
176
}
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 ) ;
177
182
}
178
183
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
+ ) ;
181
197
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 )
183
200
. interact_opt ( ) ?
184
201
. unwrap_or ( false ) ;
185
202
Ok ( choice)
@@ -196,13 +213,16 @@ fn installer_for(plugin_name: &str) -> Install {
196
213
}
197
214
}
198
215
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 > {
200
220
let Ok ( known) = plugin_store. catalogue_manifests ( ) else {
201
- return false ;
221
+ return None ;
202
222
} ;
203
223
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 ( ) )
206
226
}
207
227
208
228
async fn report_badger_result ( badger : tokio:: task:: JoinHandle < BadgerChecker > ) {
0 commit comments