mirror of
https://github.com/nushell/nushell
synced 2025-01-08 03:09:00 +00:00
d06f457b2a
* move commands, futures.rs, script.rs, utils * move over maybe_print_errors * add nu_command crate references to nu_cli * in commands.rs open up to pub mod from pub(crate) * nu-cli, nu-command, and nu tests are now passing * cargo fmt * clean up nu-cli/src/prelude.rs * code cleanup * for some reason lex.rs was not formatted, may be causing my error * remove mod completion from lib.rs which was not being used along with quickcheck macros * add in allow unused imports * comment out one failing external test; comment out one failing internal test * revert commenting out failing tests; something else might be going on; someone with a windows machine should check and see what is going on with these failing windows tests * Update Cargo.toml Extend the optional features to nu-command Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
use crate::prelude::*;
|
|
use nu_errors::ShellError;
|
|
|
|
use nu_data::value::format_leaf;
|
|
use nu_engine::WholeStreamCommand;
|
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct BuildStringArgs {
|
|
rest: Vec<Value>,
|
|
}
|
|
|
|
pub struct BuildString;
|
|
|
|
#[async_trait]
|
|
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 {
|
|
"Builds a string from the arguments"
|
|
}
|
|
|
|
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
let tag = args.call_info.name_tag.clone();
|
|
let (BuildStringArgs { rest }, _) = args.process().await?;
|
|
|
|
let mut output_string = String::new();
|
|
|
|
for r in rest {
|
|
output_string.push_str(&format_leaf(&r).plain_string(100_000))
|
|
}
|
|
|
|
Ok(OutputStream::one(ReturnSuccess::value(
|
|
UntaggedValue::string(output_string).into_value(tag),
|
|
)))
|
|
}
|
|
|
|
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,
|
|
}]
|
|
}
|
|
}
|