Use - for stdout
This commit is contained in:
parent
041d642ed4
commit
2c49f3be62
|
@ -34,7 +34,7 @@ impl Command for UTouch {
|
||||||
.rest(
|
.rest(
|
||||||
"files",
|
"files",
|
||||||
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::Filepath]),
|
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::Filepath]),
|
||||||
"The file(s) to create."
|
"The file(s) to create. '-' is used to represent stdout."
|
||||||
)
|
)
|
||||||
.named(
|
.named(
|
||||||
"reference",
|
"reference",
|
||||||
|
@ -71,7 +71,7 @@ impl Command for UTouch {
|
||||||
)
|
)
|
||||||
.switch(
|
.switch(
|
||||||
"no-dereference",
|
"no-dereference",
|
||||||
"affect each symbolic link instead of any referenced file (only for systems that can change the timestamps of a symlink)",
|
"affect each symbolic link instead of any referenced file (only for systems that can change the timestamps of a symlink). Ignored if touching stdout",
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
.category(Category::FileSystem)
|
.category(Category::FileSystem)
|
||||||
|
@ -157,8 +157,13 @@ impl Command for UTouch {
|
||||||
|
|
||||||
let mut input_files = Vec::new();
|
let mut input_files = Vec::new();
|
||||||
for file_glob in &file_globs {
|
for file_glob in &file_globs {
|
||||||
let path = expand_path_with(file_glob.item.as_ref(), &cwd, file_glob.item.is_expand());
|
if file_glob.item.as_ref() == "-" {
|
||||||
input_files.push(InputFile::Path(path));
|
input_files.push(InputFile::Stdout);
|
||||||
|
} else {
|
||||||
|
let path =
|
||||||
|
expand_path_with(file_glob.item.as_ref(), &cwd, file_glob.item.is_expand());
|
||||||
|
input_files.push(InputFile::Path(path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = uu_touch::touch(
|
if let Err(err) = uu_touch::touch(
|
||||||
|
@ -240,7 +245,7 @@ impl Command for UTouch {
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: r#"Changes the last modified time of file d and e to "fixture.json"'s last modified time"#,
|
description: r#"Changes the last modified time of files d and e to "fixture.json"'s last modified time"#,
|
||||||
example: r#"utouch -m -r fixture.json d e"#,
|
example: r#"utouch -m -r fixture.json d e"#,
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
|
@ -249,6 +254,11 @@ impl Command for UTouch {
|
||||||
example: r#"utouch -a -t 2019-08-24T12:30:30 fixture.json"#,
|
example: r#"utouch -a -t 2019-08-24T12:30:30 fixture.json"#,
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: r#"Change the last accessed and last modified times of stdout"#,
|
||||||
|
example: r#"utouch -"#,
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -528,3 +528,11 @@ fn reference_respects_cwd() {
|
||||||
assert!(path.exists());
|
assert!(path.exists());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recognizes_stdout() {
|
||||||
|
Playground::setup("utouch_recognizes_stdout", |dirs, _sandbox| {
|
||||||
|
nu!(cwd: dirs.test(), "utouch -");
|
||||||
|
assert!(!dirs.test().join("-").exists());
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user