Base Command implementation for Format

Note that run is not implemented yet
This commit is contained in:
Antonio Natilla 2021-11-02 18:13:06 +01:00
parent b53570ceaa
commit 52cb50b937
4 changed files with 59 additions and 0 deletions

View file

@ -42,6 +42,7 @@ pub fn create_default_context() -> EngineState {
External,
First,
For,
Format,
From,
FromJson,
Get,

View file

@ -0,0 +1,53 @@
//use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Format;
impl Command for Format {
fn name(&self) -> &str {
"format"
}
fn signature(&self) -> Signature {
Signature::build("format").required(
"pattern",
SyntaxShape::String,
"the pattern to output. e.g.) \"{foo}: {bar}\"",
)
}
fn usage(&self) -> &str {
"Format columns into a string using a simple pattern."
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
_call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
todo!()
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Print filenames with their sizes",
example: "ls | format '{name}: {size}'",
result: None,
}]
}
}
#[cfg(test)]
mod test {
#[test]
fn test_examples() {
use super::Format;
use crate::test_examples;
test_examples(Format {})
}
}

View file

@ -0,0 +1,3 @@
pub mod format;
pub use format::Format;

View file

@ -1,7 +1,9 @@
mod build_string;
mod format;
mod size;
mod split;
pub use build_string::BuildString;
pub use format::*;
pub use size::Size;
pub use split::*;