Merge pull request #3 from mario-kr/impl_basic-executable

Impl basic executable
This commit is contained in:
mario-kr 2016-05-11 12:55:03 +02:00
commit 66e57bf57c
3 changed files with 124 additions and 2 deletions

View file

@ -1,6 +1,22 @@
[package] [package]
authors = ["mario <mario-krehl@gmx.de>"]
name = "imag-todo" name = "imag-todo"
version = "0.1.0" version = "0.1.0"
authors = ["mario <mario-krehl@gmx.de>"]
[dependencies] [dependencies]
clap = "2.4.3"
glob = "0.2.11"
log = "0.3.6"
semver = "0.2.3"
toml = "0.1.28"
version = "2.0.1"
[dependencies.libimagstore]
path = "../libimagstore"
[dependencies.libimagrt]
path = "../libimagrt"
[dependencies.libimagutil]
path = "../libimagutil"

View file

@ -1,3 +1,67 @@
extern crate clap;
extern crate glob;
#[macro_use] extern crate log;
extern crate semver;
extern crate toml;
#[macro_use] extern crate version;
extern crate libimagrt;
extern crate libimagstore;
extern crate libimagutil;
use std::process::exit;
use libimagrt::runtime::Runtime;
use libimagstore::store::FileLockEntry;
use libimagutil::trace::trace_error;
mod ui;
use ui::build_ui;
fn main() { fn main() {
println!("Hello, world!"); 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") {
println!("To be implemented");
//
// TODO @Kevin: import function aus task_hookrs benutzen, um
// stdin auszulesen, und dann auf dem
// task_hookrs::task::Task den Trait für die
// Umwandlung aufrufen.
//
}
else if subcmd.is_present("delete") {
println!("To be implemented");
//
// Functionality to delete Entry in the store
//
}
else {
// Should not be possible, as one argument is required via
// ArgGroup
panic!("Reached unreachable Code");
}
},
Some("exec") => {
},
_ => println!("Nothing implemented yet"),
}
} }

42
imag-todo/src/ui.rs Normal file
View file

@ -0,0 +1,42 @@
use clap::{Arg, App, ArgGroup, SubCommand};
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app
.subcommand(SubCommand::with_name("tw-hook")
.about("For use in a taskwarrior hook")
.version("0.1")
.arg(Arg::with_name("add")
.long("add")
.short("a")
.takes_value(false)
.required(false)
.help("For use in an on-add hook"))
.arg(Arg::with_name("delete")
.long("delete")
.short("d")
.takes_value(false)
.required(false)
.help("For use in an on-delete hook"))
.group(ArgGroup::with_name("taskwarrior hooks")
.args(&[ "add",
"delete",
])
.required(true))
)
.subcommand(SubCommand::with_name("exec")
.about("Send a command to taskwarrior")
.version("0.1")
.arg(Arg::with_name("command")
.long("command")
.short("c")
.takes_value(true)
.required(true)
.help("Args written in the string will be send directly to taskwarrior"))
)
}