From 95ea3fcf4ef91bf3dc20d1591cb561d62b623af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Mon, 23 Sep 2019 17:01:40 -0500 Subject: [PATCH] Load plugin if and only if it hasn't been registered. --- src/cli.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index d0c70876f6..b94f824dba 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -72,21 +72,23 @@ fn load_plugin(path: &std::path::Path, context: &mut Context) -> Result<(), Shel trace!("processing {:?}", params); - if params.is_filter { - let fname = fname.to_string(); - let name = params.name.clone(); - context.add_commands(vec![whole_stream_command(PluginCommand::new( - name, fname, params, - ))]); - Ok(()) + let name = params.name.clone(); + let fname = fname.to_string(); + + if context.has_command(&name) { + trace!("plugin {:?} already loaded.", &name); } else { - let fname = fname.to_string(); - let name = params.name.clone(); - context.add_commands(vec![whole_stream_command(PluginSink::new( - name, fname, params, - ))]); - Ok(()) + if params.is_filter { + context.add_commands(vec![whole_stream_command( + PluginCommand::new(name, fname, params), + )]); + } else { + context.add_commands(vec![whole_stream_command(PluginSink::new( + name, fname, params, + ))]); + }; } + Ok(()) } Err(e) => Err(e), },