feat: update: #4518, Add example for register,source,save,shuffle and from tsv (#4577)

This commit is contained in:
Justin Ma
2022-02-21 20:25:41 +08:00
committed by GitHub
parent d454fad4dc
commit 968427c4e9
5 changed files with 84 additions and 6 deletions

View File

@ -1,7 +1,9 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value,
};
use std::io::Write;
use std::path::Path;
@ -21,7 +23,7 @@ impl Command for Save {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("save")
.required("filename", SyntaxShape::Filepath, "the filename to use")
.switch("raw", "open file as raw binary", Some('r'))
.switch("raw", "save file as raw binary", Some('r'))
.category(Category::FileSystem)
}
@ -115,4 +117,19 @@ impl Command for Save {
}
}
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Save a string to foo.txt in current directory",
example: r#"echo 'save me' | save foo.txt"#,
result: None,
},
Example {
description: "Save a record to foo.json in current directory",
example: r#"echo { a: 1, b: 2 } | save foo.json"#,
result: None,
},
]
}
}