Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn arg_iterate<'a>(
}
}

#[derive(Debug, PartialEq, Default)]
#[derive(Debug, PartialEq)]
struct HeadOptions {
pub quiet: bool,
pub verbose: bool,
Expand All @@ -138,20 +138,17 @@ struct HeadOptions {
}

impl HeadOptions {
///Construct options from matches
/// Construct options from matches
pub fn get_from(matches: &ArgMatches) -> Result<Self, String> {
let mut options = Self::default();

options.quiet = matches.get_flag(options::QUIET);
options.verbose = matches.get_flag(options::VERBOSE);
options.line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
options.presume_input_pipe = matches.get_flag(options::PRESUME_INPUT_PIPE);

options.mode = Mode::from(matches)?;

options.files = match matches.get_many::<OsString>(options::FILES) {
Some(v) => v.cloned().collect(),
None => vec![OsString::from("-")],
let options = Self {
quiet: matches.get_flag(options::QUIET),
verbose: matches.get_flag(options::VERBOSE),
line_ending: LineEnding::from_zero_flag(matches.get_flag(options::ZERO)),
presume_input_pipe: matches.get_flag(options::PRESUME_INPUT_PIPE),
mode: Mode::from(matches)?,
files: matches
.get_many::<OsString>(options::FILES)
.map_or_else(|| vec![OsString::from("-")], |v| v.cloned().collect()),
};

Ok(options)
Expand Down Expand Up @@ -581,13 +578,14 @@ mod tests {

#[test]
fn test_options_correct_defaults() {
let opts = HeadOptions::default();
let matches = uu_app().get_matches();
let opts = HeadOptions::get_from(&matches).unwrap();

assert!(!opts.verbose);
assert!(!opts.quiet);
assert_eq!(opts.line_ending, LineEnding::Newline);
assert_eq!(opts.mode, Mode::FirstLines(10));
assert!(opts.files.is_empty());
assert_eq!(opts.files, vec!(OsString::from("-")));
}

fn arg_outputs(src: &str) -> Result<String, ()> {
Expand Down
Loading