rtw 2.0.0-alpha

time tracker command line tool
Documentation
#[macro_use]
extern crate clap;

use crate::chrono_clock::ChronoClock;
use crate::cli_helper::get_app;
use crate::json_storage::JsonStorage;
use crate::rtw_cli::{dry_run_action, run, run_mutation};
use crate::rtw_config::load_config;
use crate::service::Service;
use std::path::PathBuf;
use std::str::FromStr;

mod chrono_clock;
mod cli_helper;
#[cfg(ical)]
mod ical_export;
mod ical_export;
mod json_storage;
mod rtw_cli;
mod rtw_config;
mod rtw_core;
mod service;
mod time_tools;
mod timeline;

fn main() -> anyhow::Result<()> {
    let config = load_config()?;
    let clock = ChronoClock {};
    let app = get_app();
    let matches = app.get_matches();
    let storage_dir = match matches.value_of("directory") {
        None => config.storage_dir_path.clone(),
        Some(dir_str) => PathBuf::from_str(dir_str).expect("invalid directory"),
    };
    let current_activity_path = storage_dir.join(".rtw.json");
    let finished_activity_path = storage_dir.join(".rtwh.json");
    let mut service = Service::new(JsonStorage::new(
        current_activity_path,
        finished_activity_path,
    ));

    let action = run(&matches, &clock)?;
    let mutation = dry_run_action(action, &service, &clock, &config)?;
    if matches.is_present("dry-run") {
        println!("(dry-run) nothing done");
        Ok(())
    } else {
        run_mutation(mutation, &mut service)
    }
}