support appending when saving file (#3992)

This patch implements `>>` operation in bash.

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw
2021-09-05 02:12:08 +08:00
committed by GitHub
parent 4e2d3ceaaf
commit ae9f4135c0
5 changed files with 21 additions and 4 deletions

View File

@ -142,6 +142,7 @@ impl WholeStreamCommand for Save {
"treat values as-is rather than auto-converting based on file extension",
Some('r'),
)
.switch("append", "append values rather than overriding", Some('a'))
}
fn usage(&self) -> &str {
@ -165,6 +166,7 @@ fn save(args: CommandArgs) -> Result<OutputStream, ShellError> {
let path: Option<Tagged<PathBuf>> = args.opt(0)?;
let save_raw = args.has_flag("raw");
let append = args.has_flag("append");
let input: Vec<Value> = args.input.collect();
if path.is_none() {
@ -231,7 +233,7 @@ fn save(args: CommandArgs) -> Result<OutputStream, ShellError> {
};
};
shell_manager.save(&full_path, &content?, name.span)
shell_manager.save(&full_path, &content?, name.span, append)
}
fn string_from(input: &[Value]) -> String {