@@ -52,15 +52,17 @@ pub fn main(cli: Cli) {
52
52
let args = App :: new ( "ilc" )
53
53
. version ( & version[ ..] )
54
54
. setting ( AppSettings :: GlobalVersion )
55
+ . setting ( AppSettings :: AllowLeadingHyphen )
56
+ . setting ( AppSettings :: UnifiedHelpMessage )
55
57
. setting ( AppSettings :: VersionlessSubcommands )
56
58
. setting ( AppSettings :: ArgRequiredElseHelp )
57
59
. author ( "Till Höppner <till@hoeppner.ws>" )
58
60
. 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 " )
61
63
. global ( true )
62
64
. takes_value ( true )
63
- . long ( "timezone " )
65
+ . long ( "timeoffset " )
64
66
. short ( "t" ) )
65
67
. arg ( Arg :: with_name ( "date" )
66
68
. help ( "Override the date for this log, ISO 8601, YYYY-MM-DD" )
@@ -101,6 +103,7 @@ pub fn main(cli: Cli) {
101
103
. global ( true )
102
104
. takes_value ( true )
103
105
. multiple ( true )
106
+ . number_of_values ( 1 )
104
107
. long ( "input" )
105
108
. short ( "i" ) )
106
109
. arg ( Arg :: with_name ( "output_file" )
@@ -114,24 +117,32 @@ pub fn main(cli: Cli) {
114
117
. takes_value ( false )
115
118
. long ( "notice" ) )
116
119
. 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 ) )
118
122
. 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 ) )
120
125
. 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 ) )
122
128
. subcommand ( SubCommand :: with_name ( "seen" )
123
129
. about ( "Print the last line a nick was active" )
130
+ . setting ( AppSettings :: AllowLeadingHyphen )
124
131
. arg ( Arg :: with_name ( "nick" )
125
132
. help ( "The nick you're looking for" )
126
133
. takes_value ( true )
127
134
. required ( true )
128
135
. 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 ) )
130
139
. 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 ) )
132
142
. subcommand ( SubCommand :: with_name ( "merge" )
133
143
. about ( "Merges the input logs. This has to keep everything \
134
- in memory") )
144
+ in memory")
145
+ . setting ( AppSettings :: AllowLeadingHyphen ) )
135
146
. get_matches ( ) ;
136
147
137
148
if args. is_present ( "notice" ) {
@@ -223,6 +234,21 @@ pub fn die(s: &str) -> ! {
223
234
process:: exit ( 1 )
224
235
}
225
236
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
+
226
252
pub fn decoder ( format : & str ) -> Option < Box < Decode > > {
227
253
match format {
228
254
"energymech" | "em" => Some ( Box :: new ( Energymech ) ) ,
@@ -252,7 +278,7 @@ pub fn force_decoder(s: Option<&str>) -> Box<Decode> {
252
278
} ;
253
279
match decoder ( & inf) {
254
280
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) ,
256
282
}
257
283
}
258
284
@@ -263,7 +289,7 @@ pub fn force_encoder<'a>(s: Option<&str>) -> Box<Encode> {
263
289
} ;
264
290
match encoder ( & outf) {
265
291
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) ,
267
293
}
268
294
}
269
295
@@ -306,8 +332,8 @@ impl<'a> Environment<'a> {
306
332
307
333
pub fn build_context ( args : & ArgMatches ) -> Context {
308
334
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 ( ) )
311
337
. unwrap_or ( 0 ) ) ,
312
338
override_date : args. value_of ( "date" ) . and_then ( |d| NaiveDate :: from_str ( & d) . ok ( ) ) ,
313
339
channel : args. value_of ( "channel" ) . map ( str:: to_owned) . clone ( ) ,
@@ -325,7 +351,7 @@ pub fn build_context(args: &ArgMatches) -> Context {
325
351
context. override_date = Some ( date) ;
326
352
}
327
353
}
328
- _n => die ( "Too many input files, can't infer date" ) ,
354
+ n => error ! ( 3 , "Too many input files ({}) , can't infer date" , n ) ,
329
355
}
330
356
}
331
357
context
0 commit comments