Ugh
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use log::*;
|
||||
use std::io::{self, Write};
|
||||
use std::process::{Command, Stdio, Child};
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use which::which;
|
||||
|
||||
use crate::meta_plugin::{MetaPlugin, MetaPluginResponse, MetaPluginType, BaseMetaPlugin};
|
||||
use crate::meta_plugin::{BaseMetaPlugin, MetaPlugin, MetaPluginResponse, MetaPluginType};
|
||||
|
||||
/// External program execution meta plugin.
|
||||
///
|
||||
@@ -44,7 +44,6 @@ impl std::fmt::Debug for MetaPluginExec {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl MetaPluginExec {
|
||||
/// Creates a new MetaPluginExec instance.
|
||||
///
|
||||
@@ -113,7 +112,10 @@ impl MetaPluginExec {
|
||||
}
|
||||
|
||||
if !self.supported {
|
||||
debug!("META: Exec plugin: program '{}' not supported", self.program);
|
||||
debug!(
|
||||
"META: Exec plugin: program '{}' not supported",
|
||||
self.program
|
||||
);
|
||||
return MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
@@ -138,7 +140,10 @@ impl MetaPluginExec {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("META: Exec plugin: failed to start '{}': {}", self.program, e);
|
||||
error!(
|
||||
"META: Exec plugin: failed to start '{}': {}",
|
||||
self.program, e
|
||||
);
|
||||
MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
@@ -166,10 +171,10 @@ impl MetaPlugin for MetaPluginExec {
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) -> MetaPluginResponse {
|
||||
if let Some(writer) = self.writer.as_mut() {
|
||||
if let Err(e) = writer.write_all(data) {
|
||||
error!("META: Exec plugin: failed to write to stdin: {}", e);
|
||||
}
|
||||
if let Some(writer) = self.writer.as_mut()
|
||||
&& let Err(e) = writer.write_all(data)
|
||||
{
|
||||
error!("META: Exec plugin: failed to write to stdin: {}", e);
|
||||
}
|
||||
MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
@@ -190,7 +195,11 @@ impl MetaPlugin for MetaPluginExec {
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let result = if self.split_whitespace {
|
||||
stdout.split_whitespace().next().unwrap_or(&stdout).to_string()
|
||||
stdout
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.unwrap_or(&stdout)
|
||||
.to_string()
|
||||
} else {
|
||||
stdout.trim().to_string()
|
||||
};
|
||||
@@ -198,7 +207,11 @@ impl MetaPlugin for MetaPluginExec {
|
||||
self.result = Some(result.clone());
|
||||
|
||||
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
|
||||
self.base.outputs().keys().next().unwrap_or(&"exec".to_string()),
|
||||
self.base
|
||||
.outputs()
|
||||
.keys()
|
||||
.next()
|
||||
.unwrap_or(&"exec".to_string()),
|
||||
serde_yaml::Value::String(result),
|
||||
self.base.outputs(),
|
||||
) {
|
||||
@@ -261,7 +274,8 @@ fn register_exec_plugin() {
|
||||
|
||||
if let Some(opts) = &options {
|
||||
if let Some(command_value) = opts.get("command")
|
||||
&& let Some(command_str) = command_value.as_str() {
|
||||
&& let Some(command_str) = command_value.as_str()
|
||||
{
|
||||
let parts: Vec<&str> = command_str.split_whitespace().collect();
|
||||
if !parts.is_empty() {
|
||||
program_name = parts[0].to_string();
|
||||
@@ -269,11 +283,13 @@ fn register_exec_plugin() {
|
||||
}
|
||||
}
|
||||
if let Some(split_value) = opts.get("split_whitespace")
|
||||
&& let Some(split_bool) = split_value.as_bool() {
|
||||
&& let Some(split_bool) = split_value.as_bool()
|
||||
{
|
||||
split_whitespace = split_bool;
|
||||
}
|
||||
if let Some(name_value) = opts.get("name")
|
||||
&& let Some(name_str) = name_value.as_str() {
|
||||
&& let Some(name_str) = name_value.as_str()
|
||||
{
|
||||
meta_name = name_str.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user