Skip to content

Commit 8b2f687

Browse files
committed
head: remove Default trait from HeadOptions
1 parent 7807c8d commit 8b2f687

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

src/uu/head/src/head.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn arg_iterate<'a>(
129129
}
130130
}
131131

132-
#[derive(Debug, PartialEq, Default)]
132+
#[derive(Debug, PartialEq)]
133133
struct HeadOptions {
134134
pub quiet: bool,
135135
pub verbose: bool,
@@ -140,22 +140,21 @@ struct HeadOptions {
140140
}
141141

142142
impl HeadOptions {
143-
///Construct options from matches
143+
/// Construct options from matches
144144
pub fn get_from(matches: &ArgMatches) -> Result<Self, String> {
145-
let mut options = Self::default();
146-
147-
options.quiet = matches.get_flag(options::QUIET);
148-
options.verbose = matches.get_flag(options::VERBOSE);
149-
options.line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));
150-
options.presume_input_pipe = matches.get_flag(options::PRESUME_INPUT_PIPE);
151-
152-
options.mode = Mode::from(matches)?;
153-
// #[allow(clippy::unwrap_used, reason = "clap provides '-' by default")] <https://github.com/rust-lang/rust/issues/15701>
154-
options.files = matches
155-
.get_many::<OsString>(options::FILES)
156-
.unwrap()
157-
.cloned()
158-
.collect();
145+
let options = Self {
146+
quiet: matches.get_flag(options::QUIET),
147+
verbose: matches.get_flag(options::VERBOSE),
148+
line_ending: LineEnding::from_zero_flag(matches.get_flag(options::ZERO)),
149+
presume_input_pipe: matches.get_flag(options::PRESUME_INPUT_PIPE),
150+
mode: Mode::from(matches)?,
151+
// #[allow(clippy::unwrap_used, reason = "clap provides '-' by default")] <https://github.com/rust-lang/rust/issues/15701>
152+
files: matches
153+
.get_many::<OsString>(options::FILES)
154+
.unwrap()
155+
.cloned()
156+
.collect(),
157+
};
159158

160159
Ok(options)
161160
}
@@ -604,13 +603,14 @@ mod tests {
604603

605604
#[test]
606605
fn test_options_correct_defaults() {
607-
let opts = HeadOptions::default();
606+
let matches = uu_app().get_matches();
607+
let opts = HeadOptions::get_from(&matches).unwrap();
608608

609609
assert!(!opts.verbose);
610610
assert!(!opts.quiet);
611611
assert_eq!(opts.line_ending, LineEnding::Newline);
612612
assert_eq!(opts.mode, Mode::FirstLines(10));
613-
assert!(opts.files.is_empty());
613+
assert_eq!(opts.files, vec!(OsString::from("-")));
614614
}
615615

616616
fn arg_outputs(src: &str) -> Result<String, ()> {

0 commit comments

Comments
 (0)