@@ -129,7 +129,7 @@ fn arg_iterate<'a>(
129129 }
130130}
131131
132- #[ derive( Debug , PartialEq , Default ) ]
132+ #[ derive( Debug , PartialEq ) ]
133133struct HeadOptions {
134134 pub quiet : bool ,
135135 pub verbose : bool ,
@@ -140,20 +140,17 @@ struct HeadOptions {
140140}
141141
142142impl 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-
154- options. files = match matches. get_many :: < OsString > ( options:: FILES ) {
155- Some ( v) => v. cloned ( ) . collect ( ) ,
156- None => vec ! [ OsString :: from( "-" ) ] ,
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+ files : matches
152+ . get_many :: < OsString > ( options:: FILES )
153+ . map_or_else ( || vec ! [ OsString :: from( "-" ) ] , |v| v. cloned ( ) . collect ( ) ) ,
157154 } ;
158155
159156 Ok ( options)
@@ -603,13 +600,14 @@ mod tests {
603600
604601 #[ test]
605602 fn test_options_correct_defaults ( ) {
606- let opts = HeadOptions :: default ( ) ;
603+ let matches = uu_app ( ) . get_matches ( ) ;
604+ let opts = HeadOptions :: get_from ( & matches) . unwrap ( ) ;
607605
608606 assert ! ( !opts. verbose) ;
609607 assert ! ( !opts. quiet) ;
610608 assert_eq ! ( opts. line_ending, LineEnding :: Newline ) ;
611609 assert_eq ! ( opts. mode, Mode :: FirstLines ( 10 ) ) ;
612- assert ! ( opts. files. is_empty ( ) ) ;
610+ assert_eq ! ( opts. files, vec! ( OsString :: from ( "-" ) ) ) ;
613611 }
614612
615613 fn arg_outputs ( src : & str ) -> Result < String , ( ) > {
0 commit comments