2020-05-19 21:27:26 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
use nu_errors::ShellError;
|
|
|
|
|
2020-08-18 09:00:02 +02:00
|
|
|
use nu_data::value::format_leaf;
|
2021-01-10 03:50:49 +01:00
|
|
|
use nu_engine::WholeStreamCommand;
|
2020-05-19 21:27:26 +02:00
|
|
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
|
|
|
|
|
|
|
pub struct BuildString;
|
|
|
|
|
|
|
|
impl WholeStreamCommand for BuildString {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"build-string"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("build-string")
|
|
|
|
.rest(SyntaxShape::Any, "all values to form into the string")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
2021-03-08 00:57:58 +01:00
|
|
|
"Builds a string from the arguments."
|
2020-05-19 21:27:26 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 04:35:01 +02:00
|
|
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
2020-05-30 01:36:04 +02:00
|
|
|
let tag = args.call_info.name_tag.clone();
|
2021-04-08 10:15:36 +02:00
|
|
|
let args = args.evaluate_once()?;
|
|
|
|
let rest: Vec<Value> = args.rest(0)?;
|
2020-05-30 01:36:04 +02:00
|
|
|
|
|
|
|
let mut output_string = String::new();
|
|
|
|
|
|
|
|
for r in rest {
|
|
|
|
output_string.push_str(&format_leaf(&r).plain_string(100_000))
|
|
|
|
}
|
|
|
|
|
2021-04-12 04:35:01 +02:00
|
|
|
Ok(ActionStream::one(ReturnSuccess::value(
|
2020-05-30 01:36:04 +02:00
|
|
|
UntaggedValue::string(output_string).into_value(tag),
|
|
|
|
)))
|
2020-05-19 21:27:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
|
|
vec![Example {
|
|
|
|
description: "Builds a string from a string and a number, without spaces between them",
|
|
|
|
example: "build-string 'foo' 3",
|
|
|
|
result: None,
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|