File tree Expand file tree Collapse file tree 3 files changed +20
-14
lines changed
Expand file tree Collapse file tree 3 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -648,12 +648,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
648648 } ;
649649
650650 let time = matches. contains_id ( options:: TIME ) . then ( || {
651- match matches. get_one :: < String > ( options:: TIME ) . map ( AsRef :: as_ref) {
652- None | Some ( "ctime" | "status" ) => MetadataTimeField :: Modification ,
653- Some ( "access" | "atime" | "use" ) => MetadataTimeField :: Access ,
654- Some ( "birth" | "creation" ) => MetadataTimeField :: Birth ,
655- _ => unreachable ! ( "should be caught by clap" ) ,
656- }
651+ matches
652+ . get_one :: < String > ( options:: TIME )
653+ . map_or ( MetadataTimeField :: Modification , |s| s. as_str ( ) . into ( ) )
657654 } ) ;
658655
659656 let size_format = if matches. get_flag ( options:: HUMAN_READABLE ) {
Original file line number Diff line number Diff line change @@ -464,14 +464,7 @@ fn extract_sort(options: &clap::ArgMatches) -> Sort {
464464/// A `MetadataTimeField` variant representing the time to use.
465465fn extract_time ( options : & clap:: ArgMatches ) -> MetadataTimeField {
466466 if let Some ( field) = options. get_one :: < String > ( options:: TIME ) {
467- match field. as_str ( ) {
468- "ctime" | "status" => MetadataTimeField :: Change ,
469- "access" | "atime" | "use" => MetadataTimeField :: Access ,
470- "mtime" | "modification" => MetadataTimeField :: Modification ,
471- "birth" | "creation" => MetadataTimeField :: Birth ,
472- // below should never happen as clap already restricts the values.
473- _ => unreachable ! ( "Invalid field for --time" ) ,
474- }
467+ field. as_str ( ) . into ( )
475468 } else if options. get_flag ( options:: time:: ACCESS ) {
476469 MetadataTimeField :: Access
477470 } else if options. get_flag ( options:: time:: CHANGE ) {
Original file line number Diff line number Diff line change @@ -135,6 +135,22 @@ pub enum MetadataTimeField {
135135 Birth ,
136136}
137137
138+ impl From < & str > for MetadataTimeField {
139+ /// Get a `MetadataTimeField` from a string, we expect the value
140+ /// to come from clap, and be constrained there (e.g. if Modification is
141+ /// not supported), and the default branch should not be reached.
142+ fn from ( value : & str ) -> Self {
143+ match value {
144+ "ctime" | "status" => MetadataTimeField :: Change ,
145+ "access" | "atime" | "use" => MetadataTimeField :: Access ,
146+ "mtime" | "modification" => MetadataTimeField :: Modification ,
147+ "birth" | "creation" => MetadataTimeField :: Birth ,
148+ // below should never happen as clap already restricts the values.
149+ _ => unreachable ! ( "Invalid metadata time field." ) ,
150+ }
151+ }
152+ }
153+
138154// The implementations for get_system_time are separated because some options, such
139155// as ctime will not be available
140156#[ cfg( unix) ]
You can’t perform that action at this time.
0 commit comments