libimagtimetrackfrontend/
lib.rs

1//
2// imag - the personal information management suite for the commandline
3// Copyright (C) 2015-2020 Matthias Beyer <mail@beyermatthias.de> and contributors
4//
5// This library is free software; you can redistribute it and/or
6// modify it under the terms of the GNU Lesser General Public
7// License as published by the Free Software Foundation; version
8// 2.1 of the License.
9//
10// This library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13// Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public
16// License along with this library; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18//
19
20#![forbid(unsafe_code)]
21
22#![deny(
23    non_camel_case_types,
24    non_snake_case,
25    path_statements,
26    trivial_numeric_casts,
27    unstable_features,
28    unused_allocation,
29    unused_import_braces,
30    unused_imports,
31    unused_must_use,
32    unused_mut,
33    unused_qualifications,
34    while_true,
35)]
36
37#[macro_use]
38extern crate log;
39
40extern crate clap;
41extern crate chrono;
42extern crate filters;
43extern crate itertools;
44extern crate prettytable;
45extern crate kairos;
46#[macro_use] extern crate failure;
47extern crate resiter;
48
49extern crate libimagerror;
50extern crate libimagstore;
51extern crate libimagrt;
52extern crate libimagtimetrack;
53extern crate libimagutil;
54
55mod cont;
56mod day;
57mod list;
58mod month;
59mod shell;
60mod start;
61mod stop;
62mod track;
63mod ui;
64mod week;
65mod year;
66
67use crate::cont::cont;
68use crate::day::day;
69use crate::list::{list, list_impl};
70use crate::month::month;
71use crate::shell::shell;
72use crate::start::start;
73use crate::stop::stop;
74use crate::track::track;
75use crate::week::week;
76use crate::year::year;
77
78use clap::App;
79use failure::Fallible as Result;
80use failure::err_msg;
81
82use libimagrt::runtime::Runtime;
83use libimagrt::application::ImagApplication;
84
85/// Marker enum for implementing ImagApplication on
86///
87/// This is used by binaries crates to execute business logic
88/// or to build a CLI completion.
89pub enum ImagTimetrack {}
90impl ImagApplication for ImagTimetrack {
91    fn run(rt: Runtime) -> Result<()> {
92        let command = rt.cli().subcommand_name();
93        if let Some(command) = command {
94            match command {
95                "continue" => cont(&rt),
96                "day"      => day(&rt),
97                "list"     => list(&rt),
98                "month"    => month(&rt),
99                "shell"    => shell(&rt),
100                "start"    => start(&rt),
101                "stop"     => stop(&rt),
102                "track"    => track(&rt),
103                "week"     => week(&rt),
104                "year"     => year(&rt),
105                other        => {
106                    debug!("Unknown command");
107                    if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() {
108                        Ok(())
109                    } else {
110                        Err(err_msg("Failed to handle unknown subcommand"))
111                    }
112                },
113            }
114        } else {
115            let start = ::chrono::offset::Local::today().naive_local().and_hms(0, 0, 0);
116            let end   = ::chrono::offset::Local::today().naive_local().and_hms(23, 59, 59);
117            list_impl(&rt, Some(start), Some(end), false, false)
118        }
119    }
120
121    fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
122        ui::build_ui(app)
123    }
124
125    fn name() -> &'static str {
126        env!("CARGO_PKG_NAME")
127    }
128
129    fn description() -> &'static str {
130        "Time tracking module"
131    }
132
133    fn version() -> &'static str {
134        env!("CARGO_PKG_VERSION")
135    }
136}