@@ -14,6 +14,7 @@ const ARG_ID_VERSION: &str = "version";
14
14
const ARG_ID_NUMBER_OF_QUESTIONS : & str = "num_of_questions" ;
15
15
const ARG_ID_DISABLE_LIVE_STATISTICS : & str = "disable_live_stats" ;
16
16
const ARG_ID_BEHAVIOUR_ON_ERROR : & str = "behaviour_on_err" ;
17
+ const ARG_ID_NO_COLOUR : & str = "no_colour" ;
17
18
18
19
const BEHAVIOUR_ON_ERROR_CONTINUE : & str = "continue" ;
19
20
const BEHAVIOUR_ON_ERROR_SHOW_CORRECT : & str = "showcorrect" ;
@@ -127,15 +128,19 @@ impl BehaviourOnError {
127
128
}
128
129
}
129
130
131
+ #[ allow( clippy:: struct_excessive_bools) ]
130
132
#[ derive( Debug , Clone ) ]
131
133
pub struct GeneralOptions {
132
134
pub arg_definitions : Vec < Arg > ,
135
+
133
136
pub show_help : bool ,
134
137
pub show_version : bool ,
135
138
136
139
pub number_of_questions : NumberOfQuestions ,
137
140
pub disable_live_statistics : bool ,
138
141
pub behaviour_on_error : BehaviourOnError ,
142
+
143
+ pub use_colour : bool ,
139
144
}
140
145
141
146
impl GeneralOptions {
@@ -169,13 +174,17 @@ impl GeneralOptions {
169
174
) ;
170
175
let behaviour_on_error = BehaviourOnError :: from_string ( & behaviour_on_error) ;
171
176
177
+ let use_colour =
178
+ !bool:: set_value_from_arg_or_default ( ARG_ID_NO_COLOUR , & parsed_args, & arg_definitions) ;
179
+
172
180
Ok ( Self {
173
181
arg_definitions,
174
182
show_help,
175
183
show_version,
176
184
number_of_questions,
177
185
disable_live_statistics,
178
186
behaviour_on_error,
187
+ use_colour
179
188
} )
180
189
}
181
190
@@ -244,6 +253,14 @@ impl GeneralOptions {
244
253
. stop_parsing( false )
245
254
. default_value( ArgValue :: Str ( "showcorrect" . to_string( ) ) )
246
255
. build( ) ,
256
+ Arg :: builder( )
257
+ . id( ARG_ID_NO_COLOUR )
258
+ . long_name( "no-color" )
259
+ . description( vec![ "Disable coloured output." . to_string( ) ] )
260
+ . kind( ArgKind :: Flag )
261
+ . stop_parsing( false )
262
+ . default_value( ArgValue :: Bool ( false ) )
263
+ . build( ) ,
247
264
]
248
265
}
249
266
}
@@ -317,6 +334,7 @@ mod tests {
317
334
BehaviourOnError :: ShowCorrect
318
335
) ;
319
336
assert ! ( config. skill. is_some( ) ) ;
337
+ assert ! ( config. options. use_colour) ;
320
338
}
321
339
322
340
#[ test]
@@ -326,6 +344,7 @@ mod tests {
326
344
"--number-of-questions=10" . to_string ( ) ,
327
345
"--disable-live-statistics" . to_string ( ) ,
328
346
"--behavior-on-error=repeat" . to_string ( ) ,
347
+ "--no-color" . to_string ( ) ,
329
348
"powers" . to_string ( ) ,
330
349
] ;
331
350
let config = Config :: build ( & args) . expect ( "should build successfully" ) ;
@@ -338,12 +357,14 @@ mod tests {
338
357
assert ! ( config. options. disable_live_statistics) ;
339
358
assert_eq ! ( config. options. behaviour_on_error, BehaviourOnError :: Repeat ) ;
340
359
assert ! ( config. skill. is_some( ) ) ;
360
+ assert ! ( !config. options. use_colour) ;
341
361
342
362
// Different set of args
343
363
let args = [
344
364
"command" . to_string ( ) ,
345
365
"-n" . to_string ( ) ,
346
366
"0" . to_string ( ) ,
367
+ "--no-color" . to_string ( ) ,
347
368
"-d" . to_string ( ) ,
348
369
"-b" . to_string ( ) ,
349
370
"continue" . to_string ( ) ,
@@ -362,6 +383,7 @@ mod tests {
362
383
BehaviourOnError :: NextQuestion
363
384
) ;
364
385
assert ! ( config. skill. is_some( ) ) ;
386
+ assert ! ( !config. options. use_colour) ;
365
387
}
366
388
367
389
#[ test]
0 commit comments