Merge pull request #7 from yaseleylo123/impl_exec-command

impl exec command
This commit is contained in:
mario-kr 2016-06-15 12:46:51 +02:00 committed by GitHub
commit 879160bbea
3 changed files with 37 additions and 9 deletions

View File

@ -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"

View File

@ -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") => {
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");
}
},
_ => println!("Nothing implemented yet"),
_ => panic!("Reached unreachable Code"),
}
}

View File

@ -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"))
)
}
)
}