mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 07:30:13 +01:00
Interpret lists as series of args for externals (#550)
* Interpret lists as series of args for externals * Fix clippy warnings
This commit is contained in:
parent
ea6912c3f7
commit
8ba3e3570c
@ -50,7 +50,7 @@ impl Command for External {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let mut name: Spanned<String> = call.req(engine_state, stack, 0)?;
|
let mut name: Spanned<String> = call.req(engine_state, stack, 0)?;
|
||||||
let args: Vec<String> = call.rest(engine_state, stack, 1)?;
|
let args: Vec<Value> = call.rest(engine_state, stack, 1)?;
|
||||||
let last_expression = call.has_flag("last_expression");
|
let last_expression = call.has_flag("last_expression");
|
||||||
|
|
||||||
// Translate environment variables from Values to Strings
|
// Translate environment variables from Values to Strings
|
||||||
@ -85,9 +85,34 @@ impl Command for External {
|
|||||||
return Ok(PipelineData::new(call.head));
|
return Ok(PipelineData::new(call.head));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut args_strs = vec![];
|
||||||
|
|
||||||
|
for arg in args {
|
||||||
|
if let Ok(s) = arg.as_string() {
|
||||||
|
args_strs.push(s);
|
||||||
|
} else if let Value::List { vals, .. } = arg {
|
||||||
|
// Interpret a list as a series of arguments
|
||||||
|
for val in vals {
|
||||||
|
if let Ok(s) = val.as_string() {
|
||||||
|
args_strs.push(s);
|
||||||
|
} else {
|
||||||
|
return Err(ShellError::ExternalCommand(
|
||||||
|
"Cannot convert argument to a string".into(),
|
||||||
|
val.span()?,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(ShellError::ExternalCommand(
|
||||||
|
"Cannot convert argument to a string".into(),
|
||||||
|
arg.span()?,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let command = ExternalCommand {
|
let command = ExternalCommand {
|
||||||
name,
|
name,
|
||||||
args,
|
args: args_strs,
|
||||||
last_expression,
|
last_expression,
|
||||||
env_vars: env_vars_str,
|
env_vars: env_vars_str,
|
||||||
call,
|
call,
|
||||||
|
@ -470,12 +470,12 @@ pub fn eval_variable(
|
|||||||
let mut output_vals = vec![];
|
let mut output_vals = vec![];
|
||||||
|
|
||||||
let env_vars = stack.get_env_vars();
|
let env_vars = stack.get_env_vars();
|
||||||
let env_columns: Vec<String> = env_vars.keys().map(|x| x.to_string()).collect();
|
let env_columns = env_vars.keys();
|
||||||
let env_values: Vec<Value> = env_vars.values().cloned().collect();
|
let env_values = env_vars.values();
|
||||||
|
|
||||||
let mut pairs = env_columns
|
let mut pairs = env_columns
|
||||||
.into_iter()
|
.map(|x| x.to_string())
|
||||||
.zip(env_values.into_iter())
|
.zip(env_values.cloned())
|
||||||
.collect::<Vec<(String, Value)>>();
|
.collect::<Vec<(String, Value)>>();
|
||||||
|
|
||||||
pairs.sort_by(|a, b| a.0.cmp(&b.0));
|
pairs.sort_by(|a, b| a.0.cmp(&b.0));
|
||||||
|
Loading…
Reference in New Issue
Block a user