diff --git a/imag-todo/Cargo.toml b/imag-todo/Cargo.toml index 213b2710..beac07e5 100644 --- a/imag-todo/Cargo.toml +++ b/imag-todo/Cargo.toml @@ -10,6 +10,7 @@ log = "0.3.6" semver = "0.2.3" toml = "0.1.28" version = "2.0.1" +task-hookrs = "0.1.0" [dependencies.libimagstore] path = "../libimagstore" diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index 3737baa3..96f8eafc 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -1,5 +1,6 @@ extern crate clap; extern crate glob; +extern crate task_hookrs; #[macro_use] extern crate log; extern crate semver; extern crate toml; @@ -10,20 +11,20 @@ extern crate libimagstore; extern crate libimagutil; use std::process::exit; +use std::process::{Command, Stdio}; use libimagrt::runtime::Runtime; -use libimagstore::store::FileLockEntry; -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() { @@ -35,6 +36,8 @@ fn main() { } }; + + let scmd = rt.cli().subcommand_name(); match scmd { Some("tw-hook") => { @@ -61,7 +64,29 @@ fn main() { } }, Some("exec") => { - }, - _ => println!("Nothing implemented yet"), - } + let subcmd = rt.cli().subcommand_matches("exec").unwrap(); + let mut args = Vec::new(); + if let Some(exec_string) = subcmd.values_of("command") { + for e in exec_string { + args.push(e); + } + let mut tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| { + panic!("failed to execute taskwarrior: {}", e); + }); + + let output = tw_process.wait_with_output().unwrap_or_else(|e| { + panic!("failed to unwrap output: {}", e); + }); + let outstring = String::from_utf8(output.stdout).unwrap_or_else(|e| { + panic!("failed to ececute: {}", e); + }); + println!("{}", outstring); + } else { + panic!("faild to execute: You need to exec --command"); + } + }, + _ => panic!("Reached unreachable Code"), + } + } + diff --git a/imag-todo/src/ui.rs b/imag-todo/src/ui.rs index cc675f44..d1707298 100644 --- a/imag-todo/src/ui.rs +++ b/imag-todo/src/ui.rs @@ -1,7 +1,7 @@ use clap::{Arg, App, ArgGroup, SubCommand}; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { - app + app .subcommand(SubCommand::with_name("tw-hook") .about("For use in a taskwarrior hook") .version("0.1") @@ -35,8 +35,10 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .long("command") .short("c") .takes_value(true) + .multiple(true) .required(true) .help("Args written in the string will be send directly to taskwarrior")) - ) -} + ) + +}