Skip to content

Commit 4ad8139

Browse files
committed
Add overlap and no_overlap, add tests
1 parent 4f689d5 commit 4ad8139

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

src/cli_helper.rs

+16
Original file line numberDiff line numberDiff 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")

src/main.rs

+12-1
Original file line numberDiff line numberDiff 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(),

src/rtw_config.rs

+8
Original file line numberDiff line numberDiff 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

3644
fn load_config_from_config_dir(

src/rtw_core/service.rs

+1-1
Original file line numberDiff line numberDiff 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,

tests/integration_test.rs

+31-2
Original file line numberDiff line numberDiff 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");

0 commit comments

Comments
 (0)