@@ -127,7 +127,7 @@ fn arg_iterate<'a>(
127127 }
128128}
129129
130- #[ derive( Debug , PartialEq , Default ) ]
130+ #[ derive( Debug , PartialEq ) ]
131131struct HeadOptions {
132132 pub quiet : bool ,
133133 pub verbose : bool ,
@@ -138,20 +138,18 @@ struct HeadOptions {
138138}
139139
140140impl HeadOptions {
141- ///Construct options from matches
141+ /// Construct options from matches
142142 pub fn get_from ( matches : & ArgMatches ) -> Result < Self , String > {
143- let mut options = Self :: default ( ) ;
144-
145- options. quiet = matches. get_flag ( options:: QUIET ) ;
146- options. verbose = matches. get_flag ( options:: VERBOSE ) ;
147- options. line_ending = LineEnding :: from_zero_flag ( matches. get_flag ( options:: ZERO ) ) ;
148- options. presume_input_pipe = matches. get_flag ( options:: PRESUME_INPUT_PIPE ) ;
149-
150- options. mode = Mode :: from ( matches) ?;
151-
152- options. files = match matches. get_many :: < OsString > ( options:: FILES ) {
153- Some ( v) => v. cloned ( ) . collect ( ) ,
154- None => vec ! [ OsString :: from( "-" ) ] ,
143+ let options = Self {
144+ quiet : matches. get_flag ( options:: QUIET ) ,
145+ verbose : matches. get_flag ( options:: VERBOSE ) ,
146+ line_ending : LineEnding :: from_zero_flag ( matches. get_flag ( options:: ZERO ) ) ,
147+ presume_input_pipe : matches. get_flag ( options:: PRESUME_INPUT_PIPE ) ,
148+ mode : Mode :: from ( matches) ?,
149+ files : matches
150+ . get_many :: < OsString > ( options:: FILES )
151+ . map ( |v| v. cloned ( ) . collect ( ) )
152+ . unwrap_or_else ( || vec ! [ OsString :: from( "-" ) ] ) ,
155153 } ;
156154
157155 Ok ( options)
@@ -581,13 +579,14 @@ mod tests {
581579
582580 #[ test]
583581 fn test_options_correct_defaults ( ) {
584- let opts = HeadOptions :: default ( ) ;
582+ let matches = uu_app ( ) . get_matches ( ) ;
583+ let opts = HeadOptions :: get_from ( & matches) . unwrap ( ) ;
585584
586585 assert ! ( !opts. verbose) ;
587586 assert ! ( !opts. quiet) ;
588587 assert_eq ! ( opts. line_ending, LineEnding :: Newline ) ;
589588 assert_eq ! ( opts. mode, Mode :: FirstLines ( 10 ) ) ;
590- assert ! ( opts. files. is_empty ( ) ) ;
589+ assert_eq ! ( opts. files, vec! ( OsString :: from ( "-" ) ) ) ;
591590 }
592591
593592 fn arg_outputs ( src : & str ) -> Result < String , ( ) > {
0 commit comments