File tree Expand file tree Collapse file tree 5 files changed +68
-4
lines changed
Expand file tree Collapse file tree 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> {
9292 . help ( "use default config" )
9393 . hidden ( true ) , // only useful for testing
9494 )
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+ )
95111 . arg (
96112 Arg :: with_name ( "dry-run" )
97113 . short ( "n" )
Original file line number Diff line number Diff line change @@ -25,10 +25,21 @@ fn main() -> anyhow::Result<()> {
2525 let clock = ChronoClock { } ;
2626 let app = get_app ( ) ;
2727 let matches = app. get_matches ( ) ;
28+ let config = load_config ( ) ?;
2829 let config = if matches. is_present ( "default" ) {
2930 RTWConfig :: default ( )
3031 } 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
3243 } ;
3344 let storage_dir = match matches. value_of ( "directory" ) {
3445 None => config. storage_dir_path . clone ( ) ,
Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ impl RTWConfig {
3131 deny_overlapping : true ,
3232 }
3333 }
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+ }
3442}
3543
3644fn load_config_from_config_dir (
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ pub trait ActivityService {
1919 ///
2020 /// May fail depending on backend implementation
2121 ///
22- /// Returns new current activity
22+ /// Returns new current activity and optionally the previously ongoing activity
2323 fn start_activity (
2424 & mut self ,
2525 activity : OngoingActivity ,
Original file line number Diff line number Diff line change @@ -435,7 +435,7 @@ mod tests {
435435 }
436436
437437 #[ test]
438- fn track_overlap ( ) {
438+ fn track_overlap_not_allowed ( ) {
439439 let test_dir = tempdir ( ) . expect ( "could not create temp directory" ) ;
440440 let test_dir_path = test_dir. path ( ) . to_str ( ) . unwrap ( ) ;
441441 let mut cmd = Command :: cargo_bin ( "rtw" ) . unwrap ( ) ;
@@ -452,7 +452,7 @@ mod tests {
452452 let mut cmd = Command :: cargo_bin ( "rtw" ) . unwrap ( ) ;
453453 cmd. arg ( "-d" )
454454 . arg ( test_dir_path)
455- . arg ( "--default " ) // use default config ie deny overlapping
455+ . arg ( "--no_overlap " ) // deny overlapping
456456 . arg ( "track" )
457457 . arg ( "09:30" )
458458 . arg ( "-" )
@@ -463,6 +463,35 @@ mod tests {
463463 . stderr ( predicates:: str:: contains ( "would overlap" ) ) ;
464464 }
465465
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+
466495 #[ test]
467496 fn start_nothing_now ( ) {
468497 let test_dir = tempdir ( ) . expect ( "could not create temp directory" ) ;
You can’t perform that action at this time.
0 commit comments