Skip to content

Commit 90b43fb

Browse files
committed
Merge branch 'dev'
2 parents f4d92ea + 9be70f5 commit 90b43fb

21 files changed

+81
-22
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.1](https://crates.io/crates/rtw/1.2.1) Jun 07, 2020
9+
10+
* Add warning: CLI usage stable but not `lib.rs` content.
11+
* Fix doc.rs build issue (restore `lib.rs`).
12+
813
## [1.2.0](https://crates.io/crates/rtw/1.2.0) Jun 07, 2020
914

1015
* add `cancel` subcommand.

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rtw"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
authors = ["PicoJr <picojr_dev@gmx.com>"]
55
edition = "2018"
66
repository = "https://github.com/PicoJr/rtw"

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
Command-line interface (CLI) time tracker.
1313

14+
CLI usage is stable, underlying API is **not stable**.
15+
1416
This project is heavily inspired from [Timewarrior](https://github.com/GothenburgBitFactory/timewarrior).
1517

1618
> For a stable feature-rich CLI time tracker, please use Timewarrior: https://timewarrior.net/.

src/chrono_clock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Clock impl using chrono.
12
use crate::rtw_core::clock::{Clock, Time};
23
use crate::rtw_core::datetimew::DateTimeW;
34
use chrono::{Date, Datelike, Duration, Local};

src/cli_helper.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! CLI parsing helpers and clap App.
12
use clap::{App, Arg, ArgMatches, SubCommand};
23

34
use crate::rtw_core::clock::{Clock, Time};

src/json_storage.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Store activities (current, finished) as Json files.
12
use crate::rtw_core::activity::{Activity, OngoingActivity};
23
use crate::rtw_core::storage::Storage;
34
use crate::rtw_core::ActivityId;

src/lib.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! # RTW
2+
//!
3+
//! Command-line interface (CLI) time tracker.
4+
//!
5+
//! CLI usage is stable, underlying API is **not stable**.
6+
//!
7+
//! This project is heavily inspired from [Timewarrior](https://github.com/GothenburgBitFactory/timewarrior).
8+
//!
9+
//! For a stable feature-rich CLI time tracker, please use Timewarrior: <https://timewarrior.net/>.
10+
//!
11+
//! ## Design
12+
//!
13+
//! * Activities are stored inside a `Storage`.
14+
//! * An `ActivityService` provides the logic above a storage.
15+
//! * `rtw_cli::run` translates CLI args to actions (`RTWAction`).
16+
//! * `rtw_cli::run_action` performs actions `RTWAction` by calling the service.
17+
//!
18+
//! ## Tests
19+
//!
20+
//! RTW has both unit and integration tests.
21+
22+
#[macro_use]
23+
extern crate clap;
24+
25+
pub mod chrono_clock;
26+
pub mod cli_helper;
27+
pub mod json_storage;
28+
pub mod rtw_cli;
29+
pub mod rtw_config;
30+
pub mod rtw_core;
31+
pub mod service;
32+
pub mod time_tools;
33+
mod timeline;

src/main.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
#[macro_use]
2-
extern crate clap;
3-
4-
use crate::chrono_clock::ChronoClock;
5-
use crate::json_storage::JsonStorage;
6-
use crate::rtw_cli::{run, run_action};
7-
use crate::service::Service;
1+
use rtw::chrono_clock::ChronoClock;
2+
use rtw::json_storage::JsonStorage;
3+
use rtw::rtw_cli::{run, run_action};
4+
use rtw::service::Service;
5+
use rtw::{cli_helper, rtw_config};
86
use std::path::PathBuf;
97
use std::str::FromStr;
108

11-
mod chrono_clock;
12-
mod cli_helper;
13-
mod json_storage;
14-
mod rtw_cli;
15-
mod rtw_config;
16-
mod rtw_core;
17-
mod service;
18-
mod time_tools;
19-
mod timeline;
20-
219
fn main() -> anyhow::Result<()> {
2210
let cli_helper = cli_helper::ActivityCli {};
2311
let config = rtw_config::load_config()?;
@@ -36,5 +24,6 @@ fn main() -> anyhow::Result<()> {
3624
));
3725

3826
let action = run(matches, &mut service, &clock)?;
27+
// skipping this should be the same as a dry-run.
3928
run_action(action, &mut service, &clock, &config)
4029
}

src/rtw_cli.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Translate CLI args to calls to activity Service.
12
use crate::cli_helper;
23
use crate::rtw_config::RTWConfig;
34
use crate::rtw_core::activity::{Activity, OngoingActivity};
@@ -12,7 +13,10 @@ use clap::ArgMatches;
1213

1314
type ActivityWithId = (ActivityId, Activity);
1415

15-
pub(crate) enum RTWAction {
16+
/// Describe the action (side-effect) to be made
17+
///
18+
/// see `run`
19+
pub enum RTWAction {
1620
Cancel(Option<OngoingActivity>),
1721
Start(OngoingActivity),
1822
Track(Activity),
@@ -82,7 +86,10 @@ fn run_timeline(
8286
Ok(RTWAction::Timeline(activities))
8387
}
8488

85-
pub(crate) fn run<S, Cl>(
89+
/// Translate CLI args to actions (mostly side-effect free)
90+
///
91+
/// It may fetch data from underlying activity storage but it should not write anything.
92+
pub fn run<S, Cl>(
8693
matches: ArgMatches,
8794
service: &mut Service<S>,
8895
clock: &Cl,
@@ -151,7 +158,8 @@ where
151158
}
152159
}
153160

154-
pub(crate) fn run_action<S, Cl>(
161+
/// Effectively perform the action (side effect).
162+
pub fn run_action<S, Cl>(
155163
action: RTWAction,
156164
service: &mut Service<S>,
157165
clock: &Cl,

src/rtw_config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Config.
12
extern crate config;
23

34
use self::config::FileFormat;

src/rtw_core/activity.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Activity and OngoingActivity
2+
13
use crate::rtw_core::datetimew::DateTimeW;
24
use crate::rtw_core::durationw::DurationW;
35
use crate::rtw_core::Tags;
@@ -93,6 +95,9 @@ impl OngoingActivity {
9395
}
9496
}
9597

98+
/// Check intersection between a finished activity and a date
99+
///
100+
/// Returns Some(activity) if it intersects else None.
96101
pub fn intersect(finished: &Activity, datetimew: &DateTimeW) -> Option<Activity> {
97102
if (&finished.start_time < datetimew) && (datetimew < &finished.stop_time) {
98103
Some(finished.clone())
@@ -101,6 +106,9 @@ pub fn intersect(finished: &Activity, datetimew: &DateTimeW) -> Option<Activity>
101106
}
102107
}
103108

109+
/// Check overlap between 2 finished activities
110+
///
111+
/// Returns Some(first) if first activity overlaps with the second else None.
104112
pub fn overlap(finished: &Activity, other: &Activity) -> Option<Activity> {
105113
if finished < other {
106114
intersect(finished, &other.start_time)

src/rtw_core/clock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Clock abstraction
2+
13
use crate::rtw_core::datetimew::DateTimeW;
24

35
/// Time (absolute or relative)

src/rtw_core/datetimew.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Newtype on `chrono::Date<Local>`
12
use crate::rtw_core::durationw::DurationW;
23
use crate::rtw_core::DATETIME_FMT;
34
use chrono::{DateTime, Local};

src/rtw_core/durationw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Newtype on `chrono::Duration`
12
use chrono::Duration;
23
use std::fmt;
34
use std::fmt::{Error, Formatter};

src/rtw_core/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Core traits and data structures.
12
pub mod activity;
23
pub mod clock;
34
pub mod datetimew;

src/rtw_core/service.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! A service for activities: abstracts activities queries and modifications.
12
use crate::rtw_core::activity::{Activity, OngoingActivity};
23
use crate::rtw_core::datetimew::DateTimeW;
34
use crate::rtw_core::ActivityId;

src/rtw_core/storage.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Storage: abstracts activities storage (file, memory...)
12
use crate::rtw_core::activity::{Activity, OngoingActivity};
23
use crate::rtw_core::ActivityId;
34
use std::error::Error;

src/service.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Logic above an activity storage
12
use crate::rtw_core::activity::{intersect, overlap, Activity, OngoingActivity};
23
use crate::rtw_core::datetimew::DateTimeW;
34
use crate::rtw_core::service::ActivityService;

src/time_tools.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Time parsing utils.
12
use crate::rtw_core::clock::{Clock, Time};
23
use anyhow::anyhow;
34
use chrono::Local;

src/timeline.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Timeline display
12
use crate::rtw_core::activity::Activity;
23
use crate::rtw_core::durationw::DurationW;
34
use crate::rtw_core::ActivityId;

0 commit comments

Comments
 (0)