1+ extern crate pretty_bytes;
2+ use ansi_term:: Style ;
13use chrono:: { DateTime , Utc } ;
4+ use pretty_bytes:: converter:: convert;
25use std:: os:: unix:: fs:: MetadataExt ;
3- use std:: { env, fs, io} ;
6+ use std:: { fs, io} ;
7+ use structopt:: StructOpt ;
48use termion:: color;
59use users:: { get_current_uid, get_user_by_uid} ;
6- extern crate pretty_bytes;
7- use ansi_term:: Style ;
8- use pretty_bytes:: converter:: convert;
910
10- fn main ( ) -> io:: Result < ( ) > {
11- let args: Vec < String > = env:: args ( ) . collect ( ) ;
12- let mut directory = "." ;
13- if args. len ( ) > 1 {
14- directory = & args[ 1 ]
15- }
11+ #[ derive( StructOpt , Debug ) ]
12+ struct Cli {
13+ #[ structopt( default_value = "." ) ]
14+ path : std:: path:: PathBuf ,
15+ }
16+
17+ fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
18+ let args = Cli :: from_args ( ) ;
19+ let directory = & args. path ;
1620
1721 let entries = fs:: read_dir ( directory) ?
1822 . map ( |res| res. map ( |e| e. path ( ) ) )
1923 . collect :: < Result < Vec < _ > , io:: Error > > ( ) ?;
20-
2124 let mut size_count = 0 ;
2225 for s in & entries {
2326 if convert ( fs:: metadata ( & s) ?. size ( ) as f64 ) . len ( ) > size_count {
@@ -108,7 +111,12 @@ fn main() -> io::Result<()> {
108111 print ! ( " " )
109112 }
110113 print ! ( "{}" , color:: Fg ( color:: Green ) ) ;
111- print ! ( " {}" , Style :: new( ) . bold( ) . paint( convert( fs:: metadata( & e) ?. size( ) as f64 ) ) ) ;
114+ print ! (
115+ " {}" ,
116+ Style :: new( )
117+ . bold( )
118+ . paint( convert( fs:: metadata( & e) ?. size( ) as f64 ) )
119+ ) ;
112120
113121 if let Ok ( time) = e. metadata ( ) ?. modified ( ) {
114122 print ! ( "{}" , color:: Fg ( color:: LightRed ) ) ;
@@ -120,11 +128,13 @@ fn main() -> io::Result<()> {
120128 print ! ( "{}" , color:: Fg ( color:: Yellow ) ) ;
121129 print ! (
122130 " {} " ,
123- Style :: new( ) . bold( ) . paint( get_user_by_uid( get_current_uid( ) )
124- . unwrap( )
125- . name( )
126- . to_str( )
127- . unwrap( ) )
131+ Style :: new( ) . bold( ) . paint(
132+ get_user_by_uid( get_current_uid( ) )
133+ . unwrap( )
134+ . name( )
135+ . to_str( )
136+ . unwrap( )
137+ )
128138 ) ;
129139
130140 print ! ( "{}" , color:: Fg ( color:: White ) ) ;
@@ -133,7 +143,12 @@ fn main() -> io::Result<()> {
133143 println ! ( "{}/" , & e. file_name( ) . unwrap( ) . to_str( ) . unwrap( ) ) ;
134144 } else {
135145 print ! ( "{}" , color:: Fg ( color:: LightGreen ) ) ;
136- println ! ( "{}" , Style :: new( ) . bold( ) . paint( e. file_name( ) . unwrap( ) . to_str( ) . unwrap( ) ) ) ;
146+ println ! (
147+ "{}" ,
148+ Style :: new( )
149+ . bold( )
150+ . paint( e. file_name( ) . unwrap( ) . to_str( ) . unwrap( ) )
151+ ) ;
137152 }
138153 }
139154 Ok ( ( ) )
0 commit comments