Merge pull request #7 from yaseleylo123/impl_exec-command
impl exec command
This commit is contained in:
commit
879160bbea
3 changed files with 37 additions and 9 deletions
|
@ -10,6 +10,7 @@ log = "0.3.6"
|
||||||
semver = "0.2.3"
|
semver = "0.2.3"
|
||||||
toml = "0.1.28"
|
toml = "0.1.28"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
task-hookrs = "0.1.0"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate glob;
|
extern crate glob;
|
||||||
|
extern crate task_hookrs;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
@ -10,20 +11,20 @@ extern crate libimagstore;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
use libimagutil::trace::trace_error;
|
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use ui::build_ui;
|
use ui::build_ui;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let name = "imag-todo";
|
let name = "imag-todo";
|
||||||
let version = &version!()[..];
|
let version = &version!()[..];
|
||||||
let about = "Interface with taskwarrior";
|
let about = "Interface with taskwarrior";
|
||||||
let ui = build_ui(Runtime::get_default_cli_builder(name, version, about));
|
let ui = build_ui(Runtime::get_default_cli_builder(name, version, about));
|
||||||
|
|
||||||
let rt = {
|
let rt = {
|
||||||
let rt = Runtime::new(ui);
|
let rt = Runtime::new(ui);
|
||||||
if rt.is_ok() {
|
if rt.is_ok() {
|
||||||
|
@ -35,6 +36,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let scmd = rt.cli().subcommand_name();
|
let scmd = rt.cli().subcommand_name();
|
||||||
match scmd {
|
match scmd {
|
||||||
Some("tw-hook") => {
|
Some("tw-hook") => {
|
||||||
|
@ -61,7 +64,29 @@ fn main() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some("exec") => {
|
Some("exec") => {
|
||||||
},
|
let subcmd = rt.cli().subcommand_matches("exec").unwrap();
|
||||||
_ => println!("Nothing implemented yet"),
|
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"),
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use clap::{Arg, App, ArgGroup, SubCommand};
|
use clap::{Arg, App, ArgGroup, SubCommand};
|
||||||
|
|
||||||
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
app
|
app
|
||||||
.subcommand(SubCommand::with_name("tw-hook")
|
.subcommand(SubCommand::with_name("tw-hook")
|
||||||
.about("For use in a taskwarrior hook")
|
.about("For use in a taskwarrior hook")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
|
@ -35,8 +35,10 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.long("command")
|
.long("command")
|
||||||
.short("c")
|
.short("c")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.multiple(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Args written in the string will be send directly to taskwarrior"))
|
.help("Args written in the string will be send directly to taskwarrior"))
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue