mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Base Command implementation for Format
Note that run is not implemented yet
This commit is contained in:
parent
b53570ceaa
commit
52cb50b937
4 changed files with 59 additions and 0 deletions
|
@ -42,6 +42,7 @@ pub fn create_default_context() -> EngineState {
|
|||
External,
|
||||
First,
|
||||
For,
|
||||
Format,
|
||||
From,
|
||||
FromJson,
|
||||
Get,
|
||||
|
|
53
crates/nu-command/src/strings/format/format.rs
Normal file
53
crates/nu-command/src/strings/format/format.rs
Normal 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 {})
|
||||
}
|
||||
}
|
3
crates/nu-command/src/strings/format/mod.rs
Normal file
3
crates/nu-command/src/strings/format/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod format;
|
||||
|
||||
pub use format::Format;
|
|
@ -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::*;
|
||||
|
|
Loading…
Reference in a new issue