mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #3345 from DevSabb/presume-input-pipe
head, tail: include presume-input-pipe parameter
This commit is contained in:
commit
f00ec12e4f
4 changed files with 49 additions and 4 deletions
|
@ -35,6 +35,7 @@ mod options {
|
||||||
pub const VERBOSE_NAME: &str = "VERBOSE";
|
pub const VERBOSE_NAME: &str = "VERBOSE";
|
||||||
pub const ZERO_NAME: &str = "ZERO";
|
pub const ZERO_NAME: &str = "ZERO";
|
||||||
pub const FILES_NAME: &str = "FILE";
|
pub const FILES_NAME: &str = "FILE";
|
||||||
|
pub const PRESUME_INPUT_PIPE: &str = "-PRESUME-INPUT-PIPE";
|
||||||
}
|
}
|
||||||
mod parse;
|
mod parse;
|
||||||
mod take;
|
mod take;
|
||||||
|
@ -94,6 +95,12 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.help("always print headers giving file names")
|
.help("always print headers giving file names")
|
||||||
.overrides_with_all(&[options::QUIET_NAME, options::VERBOSE_NAME]),
|
.overrides_with_all(&[options::QUIET_NAME, options::VERBOSE_NAME]),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new(options::PRESUME_INPUT_PIPE)
|
||||||
|
.long("-presume-input-pipe")
|
||||||
|
.alias("-presume-input-pipe")
|
||||||
|
.hide(true),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::ZERO_NAME)
|
Arg::new(options::ZERO_NAME)
|
||||||
.short('z')
|
.short('z')
|
||||||
|
@ -173,6 +180,7 @@ struct HeadOptions {
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
pub zeroed: bool,
|
pub zeroed: bool,
|
||||||
|
pub presume_input_pipe: bool,
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
pub files: Vec<String>,
|
pub files: Vec<String>,
|
||||||
}
|
}
|
||||||
|
@ -187,6 +195,7 @@ impl HeadOptions {
|
||||||
options.quiet = matches.is_present(options::QUIET_NAME);
|
options.quiet = matches.is_present(options::QUIET_NAME);
|
||||||
options.verbose = matches.is_present(options::VERBOSE_NAME);
|
options.verbose = matches.is_present(options::VERBOSE_NAME);
|
||||||
options.zeroed = matches.is_present(options::ZERO_NAME);
|
options.zeroed = matches.is_present(options::ZERO_NAME);
|
||||||
|
options.presume_input_pipe = matches.is_present(options::PRESUME_INPUT_PIPE);
|
||||||
|
|
||||||
options.mode = Mode::from(&matches)?;
|
options.mode = Mode::from(&matches)?;
|
||||||
|
|
||||||
|
@ -423,8 +432,8 @@ fn head_file(input: &mut std::fs::File, options: &HeadOptions) -> std::io::Resul
|
||||||
fn uu_head(options: &HeadOptions) -> UResult<()> {
|
fn uu_head(options: &HeadOptions) -> UResult<()> {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for file in &options.files {
|
for file in &options.files {
|
||||||
let res = match file.as_str() {
|
let res = match (file.as_str(), options.presume_input_pipe) {
|
||||||
"-" => {
|
(_, true) | ("-", false) => {
|
||||||
if (options.files.len() > 1 && !options.quiet) || options.verbose {
|
if (options.files.len() > 1 && !options.quiet) || options.verbose {
|
||||||
if !first {
|
if !first {
|
||||||
println!();
|
println!();
|
||||||
|
@ -460,7 +469,7 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name => {
|
(name, false) => {
|
||||||
let mut file = match std::fs::File::open(name) {
|
let mut file = match std::fs::File::open(name) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
@ -63,6 +63,7 @@ pub mod options {
|
||||||
pub static SLEEP_INT: &str = "sleep-interval";
|
pub static SLEEP_INT: &str = "sleep-interval";
|
||||||
pub static ZERO_TERM: &str = "zero-terminated";
|
pub static ZERO_TERM: &str = "zero-terminated";
|
||||||
pub static ARG_FILES: &str = "files";
|
pub static ARG_FILES: &str = "files";
|
||||||
|
pub static PRESUME_INPUT_PIPE: &str = "-presume-input-pipe";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -87,6 +88,7 @@ struct Settings {
|
||||||
follow: bool,
|
follow: bool,
|
||||||
pid: platform::Pid,
|
pid: platform::Pid,
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
|
presume_input_pipe: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
@ -148,6 +150,7 @@ impl Settings {
|
||||||
|
|
||||||
settings.verbose = matches.is_present(options::verbosity::VERBOSE);
|
settings.verbose = matches.is_present(options::verbosity::VERBOSE);
|
||||||
settings.quiet = matches.is_present(options::verbosity::QUIET);
|
settings.quiet = matches.is_present(options::verbosity::QUIET);
|
||||||
|
settings.presume_input_pipe = matches.is_present(options::PRESUME_INPUT_PIPE);
|
||||||
|
|
||||||
settings.files = match matches.values_of(options::ARG_FILES) {
|
settings.files = match matches.values_of(options::ARG_FILES) {
|
||||||
Some(v) => v.map(|s| s.to_owned()).collect(),
|
Some(v) => v.map(|s| s.to_owned()).collect(),
|
||||||
|
@ -192,7 +195,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
|
||||||
}
|
}
|
||||||
first_header = false;
|
first_header = false;
|
||||||
|
|
||||||
if use_stdin {
|
if use_stdin || settings.presume_input_pipe {
|
||||||
let mut reader = BufReader::new(stdin());
|
let mut reader = BufReader::new(stdin());
|
||||||
unbounded_tail(&mut reader, settings)?;
|
unbounded_tail(&mut reader, settings)?;
|
||||||
|
|
||||||
|
@ -339,6 +342,12 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.long(options::ZERO_TERM)
|
.long(options::ZERO_TERM)
|
||||||
.help("Line delimiter is NUL, not newline"),
|
.help("Line delimiter is NUL, not newline"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new(options::PRESUME_INPUT_PIPE)
|
||||||
|
.long(options::PRESUME_INPUT_PIPE)
|
||||||
|
.alias(options::PRESUME_INPUT_PIPE)
|
||||||
|
.hide(true),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::ARG_FILES)
|
Arg::new(options::ARG_FILES)
|
||||||
.multiple_occurrences(true)
|
.multiple_occurrences(true)
|
||||||
|
|
|
@ -342,3 +342,21 @@ fn test_head_num_with_undocumented_sign_bytes() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("abcde");
|
.stdout_is("abcde");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_presume_input_pipe_default() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["---presume-input-pipe"])
|
||||||
|
.pipe_in_fixture(INPUT)
|
||||||
|
.run()
|
||||||
|
.stdout_is_fixture("lorem_ipsum_default.expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_presume_input_pipe_5_chars() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-c", "5", "---presume-input-pipe"])
|
||||||
|
.pipe_in_fixture(INPUT)
|
||||||
|
.run()
|
||||||
|
.stdout_is_fixture("lorem_ipsum_5_chars.expected");
|
||||||
|
}
|
||||||
|
|
|
@ -563,3 +563,12 @@ fn test_lines_zero_terminated() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("b\0c\0d\0e\0");
|
.stdout_only("b\0c\0d\0e\0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_presume_input_pipe_default() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("---presume-input-pipe")
|
||||||
|
.pipe_in_fixture(FOOBAR_TXT)
|
||||||
|
.run()
|
||||||
|
.stdout_is_fixture("foobar_stdin_default.expected");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue