<commit_before>extern crate clap;
extern crate glob;
#[macro_use] extern crate log;
extern crate serde_json;
extern crate semver;
extern crate toml;
#[macro_use] extern crate version;

extern crate task_hookrs;

extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
extern crate libimagtodo;

use std::process::exit;
use std::process::{Command, Stdio};
use std::io::stdin;
use std::io::BufRead;

use task_hookrs::import::{import, import_task, import_tasks};

use libimagrt::runtime::Runtime;
use libimagtodo::task::IntoTask;
use libimagutil::trace::trace_error;

mod ui;

use ui::build_ui;
fn main() {

    let name = "imag-todo";
    let version = &version!()[..];
    let about = "Interface with taskwarrior";
    let ui = build_ui(Runtime::get_default_cli_builder(name, version, about));

    let rt = {
        let rt = Runtime::new(ui);
        if rt.is_ok() {
            rt.unwrap()
        } else {
            println!("Could not set up Runtime");
            println!("{:?}", rt.unwrap_err());
            exit(1);
        }
    };



    let scmd = rt.cli().subcommand_name();
    match scmd {
        Some("tw-hook") => {
            let subcmd = rt.cli().subcommand_matches("tw-hook").unwrap();
            if subcmd.is_present("add") {
                let stdin = stdin();
                let mut stdin = stdin.lock();
                let mut line = String::new();
                match stdin.read_line(&mut line) {
                    Ok(_) => { }
                    Err(e) => {
                        error!("{}", e);
                        return;
                    }
                };
                if let Ok(ttask) = import_task(&line.as_str()) {
                    let uuid = *ttask.uuid();
                    println!("{}", match serde_json::ser::to_string(&ttask) {
                        Ok(val) => val,
                        Err(e) => {
                            error!("{}", e);
                            return;
                        }
                    });
                    match ttask.into_filelockentry(rt.store()) {
                        Ok(val) => {
                            println!("Task {} stored in imag", uuid);
                            val
                        },
                        Err(e) => {
                            trace_error(&e);
                            error!("{}", e);
                            return;
                        }
                    };
                }
                else {
                    error!("No usable input");
                    return;
                }
            }
            else if subcmd.is_present("delete") {
                // The used hook is "on-modify". This hook gives two json-objects
                // per usage und wants one (the second one) back.
                let mut counter = 0;
                let stdin = stdin();
                let mut stdin = stdin.lock();
                if let Ok(ttasks) = import_tasks(stdin) {
                    for ttask in ttasks {
                        if counter % 2 == 1 {
                            // Only every second task is needed, the first one is the
                            // task before the change, and the second one after
                            // the change. The (maybe modified) second one is
                            // expected by taskwarrior.
                            println!("{}", match serde_json::ser::to_string(&ttask) {
                                Ok(val) => val,
                                Err(e) => {
                                    error!("{}", e);
                                    return;
                                }
                            });
                            match ttask.status() {
                                &task_hookrs::status::TaskStatus::Deleted => {
                                    match libimagtodo::delete::delete(rt.store(), *ttask.uuid()) {
                                        Ok(_) => {
                                            println!("Deleted task {}", *ttask.uuid());<commit_msg>reduce warnings<commit_after>extern crate clap;
extern crate glob;
#[macro_use] extern crate log;
extern crate serde_json;
extern crate semver;
extern crate toml;
#[macro_use] extern crate version;

extern crate task_hookrs;

extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
extern crate libimagtodo;

use std::process::exit;
use std::process::{Command, Stdio};
use std::io::stdin;
use std::io::BufRead;

use task_hookrs::import::{import_task, import_tasks};

use libimagrt::runtime::Runtime;
use libimagtodo::task::IntoTask;
use libimagutil::trace::trace_error;

mod ui;

use ui::build_ui;
fn main() {

    let name = "imag-todo";
    let version = &version!()[..];
    let about = "Interface with taskwarrior";
    let ui = build_ui(Runtime::get_default_cli_builder(name, version, about));

    let rt = {
        let rt = Runtime::new(ui);
        if rt.is_ok() {
            rt.unwrap()
        } else {
            println!("Could not set up Runtime");
            println!("{:?}", rt.unwrap_err());
            exit(1);
        }
    };



    let scmd = rt.cli().subcommand_name();
    match scmd {
        Some("tw-hook") => {
            let subcmd = rt.cli().subcommand_matches("tw-hook").unwrap();
            if subcmd.is_present("add") {
                let stdin = stdin();
                let mut stdin = stdin.lock();
                let mut line = String::new();
                match stdin.read_line(&mut line) {
                    Ok(_) => { }
                    Err(e) => {
                        error!("{}", e);
                        return;
                    }
                };
                if let Ok(ttask) = import_task(&line.as_str()) {
                    let uuid = *ttask.uuid();
                    println!("{}", match serde_json::ser::to_string(&ttask) {
                        Ok(val) => val,
                        Err(e) => {
                            error!("{}", e);
                            return;
                        }
                    });
                    match ttask.into_filelockentry(rt.store()) {
                        Ok(val) => {
                            println!("Task {} stored in imag", uuid);
                            val
                        },
                        Err(e) => {
                            trace_error(&e);
                            error!("{}", e);
                            return;
                        }
                    };
                }
                else {
                    error!("No usable input");
                    return;
                }
            }
            else if subcmd.is_present("delete") {
                // The used hook is "on-modify". This hook gives two json-objects
                // per usage und wants one (the second one) back.
                let mut counter = 0;
                let stdin = stdin();
                let stdin = stdin.lock();
                if let Ok(ttasks) = import_tasks(stdin) {
                    for ttask in ttasks {
                        if counter % 2 == 1 {
                            // Only every second task is needed, the first one is the
                            // task before the change, and the second one after
                            // the change. The (maybe modified) second one is
                            // expected by taskwarrior.
                            println!("{}", match serde_json::ser::to_string(&ttask) {
                                Ok(val) => val,
                                Err(e) => {
                                    error!("{}", e);
                                    return;
                                }
                            });
                            match ttask.status() {
                                &task_hookrs::status::TaskStatus::Deleted => {
                                    match libimagtodo::delete::delete(rt.store(), *ttask.uuid()) {
                                        Ok(_) => {
                                            println!("Deleted task {}", *ttask.uuid());
{'fraction_non_alphanumeric': 0.11679277520136686, 'fraction_numerical': 0.000976324139614352, 'mean_word_length': 1.0778397565922921, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '314562', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2020, 'n_words': 510}