From 7dbf7e7d3975500ece2cf7091c3dbe0d0ca6720a Mon Sep 17 00:00:00 2001 From: Yase Date: Wed, 1 Jun 2016 16:05:43 +0200 Subject: [PATCH 1/6] cmd query --- imag-todo/src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index 3737baa3..bef9f7a9 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -61,7 +61,17 @@ fn main() { } }, Some("exec") => { - }, - _ => println!("Nothing implemented yet"), + let subcmd = rt.cli().subcommand_matches("exec").unwrap(); + let itr = subcmd.values_of_os("add").unwrap(); + if subcmd.is_present("command") { + let string = subcmd.value_of("command").unwrap(); + println!("{:?}", string); + else { + panic!("Reached unreachable Code"); + } + }, + _ => println!("Nothing implemented yet"), + } } } + From 0545b6d3367034b17c44ed6b7e50e46a62a6938e Mon Sep 17 00:00:00 2001 From: Yase Date: Tue, 7 Jun 2016 23:45:49 +0200 Subject: [PATCH 2/6] ui.rs needed a multiple(true) main.rs - now we get the string argument of exec --command --- imag-todo/src/main.rs | 33 ++++++++++++++++++++++++--------- imag-todo/src/ui.rs | 8 +++++--- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index bef9f7a9..4ee5a240 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -10,10 +10,16 @@ extern crate libimagstore; extern crate libimagutil; use std::process::exit; +use std::process::{Command, Stdio}; +use std::io::prelude::*; +use std::io::BufReader; +use std::fs::File; use libimagrt::runtime::Runtime; use libimagstore::store::FileLockEntry; use libimagutil::trace::trace_error; +use std::error::Error; +use std::env; mod ui; @@ -24,6 +30,7 @@ fn main() { 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 +42,8 @@ fn main() { } }; + + let scmd = rt.cli().subcommand_name(); match scmd { Some("tw-hook") => { @@ -61,17 +70,23 @@ fn main() { } }, Some("exec") => { - let subcmd = rt.cli().subcommand_matches("exec").unwrap(); - let itr = subcmd.values_of_os("add").unwrap(); - if subcmd.is_present("command") { - let string = subcmd.value_of("command").unwrap(); - println!("{:?}", string); - else { - panic!("Reached unreachable Code"); - } + let subcmd = rt.cli().subcommand_matches("exec").unwrap(); + let mut string = String::from(""); + //let args: Vec<_> = env::args().collect(); + //println!("{:?}", args); + if let Some(execString) = subcmd.values_of("command") { + for e in execString { + string.push_str(e); + string.push_str(" "); + } + //NOW SEND "string" to taskwarrior + + } else { + println!("false"); + } }, _ => println!("Nothing implemented yet"), } - } + } 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")) - ) -} + ) + +} From 2fec50fc102be8f83dbee96171ce93851587f2c5 Mon Sep 17 00:00:00 2001 From: Yase Date: Wed, 8 Jun 2016 14:25:29 +0200 Subject: [PATCH 3/6] exec command calls taskwarrior --- imag-todo/src/main.rs | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index 4ee5a240..84696baa 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; @@ -11,15 +12,12 @@ extern crate libimagutil; use std::process::exit; use std::process::{Command, Stdio}; -use std::io::prelude::*; -use std::io::BufReader; -use std::fs::File; +use std::error::Error; use libimagrt::runtime::Runtime; -use libimagstore::store::FileLockEntry; -use libimagutil::trace::trace_error; -use std::error::Error; -use std::env; +use std::process::Output; +use std::io::Write; +use std::io::Read; mod ui; @@ -71,21 +69,30 @@ fn main() { }, Some("exec") => { let subcmd = rt.cli().subcommand_matches("exec").unwrap(); - let mut string = String::from(""); - //let args: Vec<_> = env::args().collect(); - //println!("{:?}", args); - if let Some(execString) = subcmd.values_of("command") { - for e in execString { - string.push_str(e); - string.push_str(" "); + let mut args = Vec::new(); + if let Some(exec_string) = subcmd.values_of("command") { + for e in exec_string { + args.push(e); } - //NOW SEND "string" to taskwarrior - + let mut tw_process = Command::new("/usr/local/bin/task").stdin(Stdio::null()).args(&args).spawn().unwrap(); + //let erg = tw_process.args(&args).spawn().unwrap(); //{ + // Ok(_) => debug!("Executed command:\n"), + // Err(e) => debug!("Failed to execute command: {:#?}", e), + //} + let output = tw_process.wait_with_output().unwrap(); + let outstring = String::from_utf8(output.stdout).unwrap(); + println!("{}", outstring); + //let mut s = String::new(); + //match tw_process.stdout.unwrap().read_to_string(&mut s) { + //Err(err) => panic!("couldn't read taskwarrior stdout: {}", + // err.description()), + //Ok(_) => print!("taskwarrior responded with:\n{}", s), + //} } else { - println!("false"); + println!("You need '--command'"); } }, - _ => println!("Nothing implemented yet"), + _ => panic!("Reached unreachable Code"), } } From 41ae20c0497acf71f87c12d55560b0397debc6ef Mon Sep 17 00:00:00 2001 From: Yase Date: Thu, 9 Jun 2016 17:21:24 +0200 Subject: [PATCH 4/6] error handling for unwrap process stuff on exec taskwarrior --- imag-todo/src/main.rs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index 84696baa..00976a5f 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -12,18 +12,14 @@ extern crate libimagutil; use std::process::exit; use std::process::{Command, Stdio}; -use std::error::Error; use libimagrt::runtime::Runtime; -use std::process::Output; -use std::io::Write; -use std::io::Read; mod ui; use ui::build_ui; - fn main() { + let name = "imag-todo"; let version = &version!()[..]; let about = "Interface with taskwarrior"; @@ -74,22 +70,19 @@ fn main() { for e in exec_string { args.push(e); } - let mut tw_process = Command::new("/usr/local/bin/task").stdin(Stdio::null()).args(&args).spawn().unwrap(); - //let erg = tw_process.args(&args).spawn().unwrap(); //{ - // Ok(_) => debug!("Executed command:\n"), - // Err(e) => debug!("Failed to execute command: {:#?}", e), - //} - let output = tw_process.wait_with_output().unwrap(); - let outstring = String::from_utf8(output.stdout).unwrap(); + let mut tw_process = Command::new("/usr/local/bin/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); - //let mut s = String::new(); - //match tw_process.stdout.unwrap().read_to_string(&mut s) { - //Err(err) => panic!("couldn't read taskwarrior stdout: {}", - // err.description()), - //Ok(_) => print!("taskwarrior responded with:\n{}", s), - //} } else { - println!("You need '--command'"); + panic!("faild to execute: You need to exec --command"); } }, _ => panic!("Reached unreachable Code"), From ba600f1fb216f3ac4495923ecd528a6bd75148ca Mon Sep 17 00:00:00 2001 From: Yase Date: Fri, 10 Jun 2016 22:16:12 +0200 Subject: [PATCH 5/6] cargo --- imag-todo/Cargo.toml | 1 + 1 file changed, 1 insertion(+) 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" From f015223a8edbf768e542709fc7a99845e3dd3eec Mon Sep 17 00:00:00 2001 From: Yase Date: Mon, 13 Jun 2016 11:15:02 +0200 Subject: [PATCH 6/6] changed /usr/bin/local/task to task --- imag-todo/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index 00976a5f..96f8eafc 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -70,7 +70,7 @@ fn main() { for e in exec_string { args.push(e); } - let mut tw_process = Command::new("/usr/local/bin/task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| { + let mut tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| { panic!("failed to execute taskwarrior: {}", e); });