@@ -52,15 +52,17 @@ pub fn main(cli: Cli) {
5252 let args = App :: new ( "ilc" )
5353 . version ( & version[ ..] )
5454 . setting ( AppSettings :: GlobalVersion )
55+ . setting ( AppSettings :: AllowLeadingHyphen )
56+ . setting ( AppSettings :: UnifiedHelpMessage )
5557 . setting ( AppSettings :: VersionlessSubcommands )
5658 . setting ( AppSettings :: ArgRequiredElseHelp )
5759 . author ( "Till Höppner <till@hoeppner.ws>" )
5860 . about ( "A converter and statistics utility for IRC log files" )
59- . arg ( Arg :: with_name ( "timezone " )
60- . help ( "UTC offset in the direction of the western hemisphere " )
61+ . arg ( Arg :: with_name ( "time " )
62+ . help ( "Timestamp offset, in seconds " )
6163 . global ( true )
6264 . takes_value ( true )
63- . long ( "timezone " )
65+ . long ( "timeoffset " )
6466 . short ( "t" ) )
6567 . arg ( Arg :: with_name ( "date" )
6668 . help ( "Override the date for this log, ISO 8601, YYYY-MM-DD" )
@@ -101,6 +103,7 @@ pub fn main(cli: Cli) {
101103 . global ( true )
102104 . takes_value ( true )
103105 . multiple ( true )
106+ . number_of_values ( 1 )
104107 . long ( "input" )
105108 . short ( "i" ) )
106109 . arg ( Arg :: with_name ( "output_file" )
@@ -114,24 +117,32 @@ pub fn main(cli: Cli) {
114117 . takes_value ( false )
115118 . long ( "notice" ) )
116119 . subcommand ( SubCommand :: with_name ( "parse" )
117- . about ( "Parse the input, checking the format" ) )
120+ . about ( "Parse the input, checking the format" )
121+ . setting ( AppSettings :: AllowLeadingHyphen ) )
118122 . subcommand ( SubCommand :: with_name ( "convert" )
119- . about ( "Convert from a source to a target format" ) )
123+ . about ( "Convert from a source to a target format" )
124+ . setting ( AppSettings :: AllowLeadingHyphen ) )
120125 . subcommand ( SubCommand :: with_name ( "stats" )
121- . about ( "Analyse the activity of users by certain metrics" ) )
126+ . about ( "Analyse the activity of users by certain metrics" )
127+ . setting ( AppSettings :: AllowLeadingHyphen ) )
122128 . subcommand ( SubCommand :: with_name ( "seen" )
123129 . about ( "Print the last line a nick was active" )
130+ . setting ( AppSettings :: AllowLeadingHyphen )
124131 . arg ( Arg :: with_name ( "nick" )
125132 . help ( "The nick you're looking for" )
126133 . takes_value ( true )
127134 . required ( true )
128135 . index ( 1 ) ) )
129- . subcommand ( SubCommand :: with_name ( "sort" ) . about ( "Sorts a log by time" ) )
136+ . subcommand ( SubCommand :: with_name ( "sort" )
137+ . about ( "Sorts a log by time" )
138+ . setting ( AppSettings :: AllowLeadingHyphen ) )
130139 . subcommand ( SubCommand :: with_name ( "dedup" )
131- . about ( "Removes duplicate log entries in close proximity" ) )
140+ . about ( "Removes duplicate log entries in close proximity" )
141+ . setting ( AppSettings :: AllowLeadingHyphen ) )
132142 . subcommand ( SubCommand :: with_name ( "merge" )
133143 . about ( "Merges the input logs. This has to keep everything \
134- in memory") )
144+ in memory")
145+ . setting ( AppSettings :: AllowLeadingHyphen ) )
135146 . get_matches ( ) ;
136147
137148 if args. is_present ( "notice" ) {
@@ -223,6 +234,21 @@ pub fn die(s: &str) -> ! {
223234 process:: exit ( 1 )
224235}
225236
237+ macro_rules! error {
238+ ( $code: expr, $fmt: expr) => { {
239+ use std:: io:: Write ;
240+ let err = std:: io:: stderr( ) ;
241+ let _ = writeln!( & mut err. lock( ) , $fmt) ;
242+ std:: process:: exit( $code) ;
243+ } } ;
244+ ( $code: expr, $fmt: expr, $( $arg: tt) * ) => { {
245+ use std:: io:: Write ;
246+ let err = std:: io:: stderr( ) ;
247+ let _ = writeln!( & mut err. lock( ) , $fmt, $( $arg) * ) ;
248+ std:: process:: exit( $code) ;
249+ } } ;
250+ }
251+
226252pub fn decoder ( format : & str ) -> Option < Box < Decode > > {
227253 match format {
228254 "energymech" | "em" => Some ( Box :: new ( Energymech ) ) ,
@@ -252,7 +278,7 @@ pub fn force_decoder(s: Option<&str>) -> Box<Decode> {
252278 } ;
253279 match decoder ( & inf) {
254280 Some ( d) => d,
255- None => die ( & format ! ( "The format `{}` is unknown to me" , inf) ) ,
281+ None => error ! ( 2 , "The format `{}` is unknown to me" , inf) ,
256282 }
257283}
258284
@@ -263,7 +289,7 @@ pub fn force_encoder<'a>(s: Option<&str>) -> Box<Encode> {
263289 } ;
264290 match encoder ( & outf) {
265291 Some ( e) => e,
266- None => die ( & format ! ( "The format `{}` is unknown to me" , outf) ) ,
292+ None => error ! ( 2 , "The format `{}` is unknown to me" , outf) ,
267293 }
268294}
269295
@@ -306,8 +332,8 @@ impl<'a> Environment<'a> {
306332
307333pub fn build_context ( args : & ArgMatches ) -> Context {
308334 let mut context = Context {
309- timezone : FixedOffset :: west ( args. value_of ( "timezone " )
310- . and_then ( |s| s. parse ( ) . ok ( ) )
335+ timezone : FixedOffset :: west ( args. value_of ( "time " )
336+ . and_then ( |s| s. parse :: < i32 > ( ) . ok ( ) )
311337 . unwrap_or ( 0 ) ) ,
312338 override_date : args. value_of ( "date" ) . and_then ( |d| NaiveDate :: from_str ( & d) . ok ( ) ) ,
313339 channel : args. value_of ( "channel" ) . map ( str:: to_owned) . clone ( ) ,
@@ -325,7 +351,7 @@ pub fn build_context(args: &ArgMatches) -> Context {
325351 context. override_date = Some ( date) ;
326352 }
327353 }
328- _n => die ( "Too many input files, can't infer date" ) ,
354+ n => error ! ( 3 , "Too many input files ({}) , can't infer date" , n ) ,
329355 }
330356 }
331357 context
0 commit comments