Commit 4ad8139 1 parent 4f689d5 commit 4ad8139 Copy full SHA for 4ad8139
File tree 5 files changed +68
-4
lines changed
5 files changed +68
-4
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,22 @@ pub fn get_app() -> App<'static, 'static> {
92
92
. help ( "use default config" )
93
93
. hidden ( true ) , // only useful for testing
94
94
)
95
+ . arg (
96
+ Arg :: with_name ( "overlap" )
97
+ . long ( "overlap" )
98
+ . required ( false )
99
+ . conflicts_with ( "default" )
100
+ . conflicts_with ( "no_overlap" )
101
+ . help ( "allow overlapping activities" ) ,
102
+ )
103
+ . arg (
104
+ Arg :: with_name ( "no_overlap" )
105
+ . long ( "no_overlap" )
106
+ . required ( false )
107
+ . conflicts_with ( "overlap" )
108
+ . conflicts_with ( "default" )
109
+ . help ( "disallow overlapping activities" ) ,
110
+ )
95
111
. arg (
96
112
Arg :: with_name ( "dry-run" )
97
113
. short ( "n" )
Original file line number Diff line number Diff line change @@ -25,10 +25,21 @@ fn main() -> anyhow::Result<()> {
25
25
let clock = ChronoClock { } ;
26
26
let app = get_app ( ) ;
27
27
let matches = app. get_matches ( ) ;
28
+ let config = load_config ( ) ?;
28
29
let config = if matches. is_present ( "default" ) {
29
30
RTWConfig :: default ( )
30
31
} else {
31
- load_config ( ) ?
32
+ config
33
+ } ;
34
+ let config = if matches. is_present ( "overlap" ) {
35
+ config. deny_overlapping ( false )
36
+ } else {
37
+ config
38
+ } ;
39
+ let config = if matches. is_present ( "no_overlap" ) {
40
+ config. deny_overlapping ( true )
41
+ } else {
42
+ config
32
43
} ;
33
44
let storage_dir = match matches. value_of ( "directory" ) {
34
45
None => config. storage_dir_path . clone ( ) ,
Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ impl RTWConfig {
31
31
deny_overlapping : true ,
32
32
}
33
33
}
34
+
35
+ pub fn deny_overlapping ( self , deny : bool ) -> Self {
36
+ RTWConfig {
37
+ storage_dir_path : self . storage_dir_path ,
38
+ timeline_colors : self . timeline_colors ,
39
+ deny_overlapping : deny,
40
+ }
41
+ }
34
42
}
35
43
36
44
fn load_config_from_config_dir (
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ pub trait ActivityService {
19
19
///
20
20
/// May fail depending on backend implementation
21
21
///
22
- /// Returns new current activity
22
+ /// Returns new current activity and optionally the previously ongoing activity
23
23
fn start_activity (
24
24
& mut self ,
25
25
activity : OngoingActivity ,
Original file line number Diff line number Diff line change @@ -435,7 +435,7 @@ mod tests {
435
435
}
436
436
437
437
#[ test]
438
- fn track_overlap ( ) {
438
+ fn track_overlap_not_allowed ( ) {
439
439
let test_dir = tempdir ( ) . expect ( "could not create temp directory" ) ;
440
440
let test_dir_path = test_dir. path ( ) . to_str ( ) . unwrap ( ) ;
441
441
let mut cmd = Command :: cargo_bin ( "rtw" ) . unwrap ( ) ;
@@ -452,7 +452,7 @@ mod tests {
452
452
let mut cmd = Command :: cargo_bin ( "rtw" ) . unwrap ( ) ;
453
453
cmd. arg ( "-d" )
454
454
. arg ( test_dir_path)
455
- . arg ( "--default " ) // use default config ie deny overlapping
455
+ . arg ( "--no_overlap " ) // deny overlapping
456
456
. arg ( "track" )
457
457
. arg ( "09:30" )
458
458
. arg ( "-" )
@@ -463,6 +463,35 @@ mod tests {
463
463
. stderr ( predicates:: str:: contains ( "would overlap" ) ) ;
464
464
}
465
465
466
+ #[ test]
467
+ fn track_overlap_allowed ( ) {
468
+ let test_dir = tempdir ( ) . expect ( "could not create temp directory" ) ;
469
+ let test_dir_path = test_dir. path ( ) . to_str ( ) . unwrap ( ) ;
470
+ let mut cmd = Command :: cargo_bin ( "rtw" ) . unwrap ( ) ;
471
+ cmd. arg ( "-d" )
472
+ . arg ( test_dir_path)
473
+ . arg ( "track" )
474
+ . arg ( "09:00" )
475
+ . arg ( "-" )
476
+ . arg ( "10:00" )
477
+ . arg ( "foo" )
478
+ . assert ( )
479
+ . success ( )
480
+ . stdout ( predicates:: str:: contains ( "Recorded foo" ) ) ;
481
+ let mut cmd = Command :: cargo_bin ( "rtw" ) . unwrap ( ) ;
482
+ cmd. arg ( "-d" )
483
+ . arg ( test_dir_path)
484
+ . arg ( "--overlap" ) // deny overlapping
485
+ . arg ( "track" )
486
+ . arg ( "09:30" )
487
+ . arg ( "-" )
488
+ . arg ( "11:00" )
489
+ . arg ( "bar" )
490
+ . assert ( )
491
+ . success ( )
492
+ . stdout ( predicates:: str:: contains ( "Recorded bar" ) ) ;
493
+ }
494
+
466
495
#[ test]
467
496
fn start_nothing_now ( ) {
468
497
let test_dir = tempdir ( ) . expect ( "could not create temp directory" ) ;
You can’t perform that action at this time.
0 commit comments