summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-02-24 19:31:11 +0100
committerNora <nora.widdecke@tu-bs.de>2019-02-24 19:31:11 +0100
commit65d8add7122a538cc2b8ab15faeb0f6351d399df (patch)
tree2e435cec1e1d3f1265e4a713581c2b4f3d7c5632 /src
parentdbead41827e93896c88ea3fe7984d3a6e17b5479 (diff)
make agenda work
Diffstat (limited to 'src')
-rw-r--r--src/bin/khaleesi.rs77
1 files changed, 40 insertions, 37 deletions
diff --git a/src/bin/khaleesi.rs b/src/bin/khaleesi.rs
index d67d1c6..dd6990d 100644
--- a/src/bin/khaleesi.rs
+++ b/src/bin/khaleesi.rs
@@ -5,6 +5,7 @@ use khaleesi::config::Config;
use khaleesi::KhResult;
use std::env;
+use structopt::clap::ArgMatches;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
@@ -14,11 +15,18 @@ struct Khaleesi {
#[structopt(short = "v", parse(from_occurrences))]
verbosity: u64,
#[structopt(subcommand)]
- cmd: Index,
+ cmd: Command,
}
#[derive(Debug, StructOpt)]
-enum Index {
+enum Command {
+ /// Show agenda view
+ #[structopt(name = "agenda")]
+ Agenda {
+ /// Rebuild index
+ #[structopt(name = "args")]
+ args: Vec<String>,
+ },
/// Rebuild index
#[structopt(name = "index")]
Index {
@@ -48,9 +56,9 @@ fn main() {
#[cfg(debug_assertions)]
init_logger(3 + args.occurrences_of("verbosity"));
- //let args: Vec<String> = env::args().collect();
- //let config = Config::read_config();
+ let config = Config::read_config();
+ //let args: Vec<String> = env::args().collect();
//let binary_name = &args[0].split('/').last().unwrap();
//let mut args = args[1..].iter().map(|s| s.as_str()).collect::<Vec<&str>>();
//if *binary_name != "khaleesi" && binary_name.starts_with("kh") {
@@ -58,40 +66,36 @@ fn main() {
// args.push(command);
// args.rotate_right(1);
//}
- //let result = main_internal(binary_name, &args[..], &config);
- //if let Err(error) = result {
- // error!("{}", error)
- //}
+ let result = main_internal(&args, &config);
+ if let Err(error) = result {
+ error!("{}", error)
+ }
}
-fn main_internal(binary_name: &str, args: &[&str], config: &Config) -> KhResult<()> {
- if args.is_empty() {
- print_usage(&binary_name);
- Ok(())
- } else {
- let cmd = args[0];
- let args = &args[1..];
- match cmd {
- // "agenda" => agenda::show_events(&config, args),
- // "copy" => copy::do_copy(args),
- // "cursor" => cursor::do_cursor(args),
- // "delete" => delete::do_delete(args),
- // "edit" => edit::do_edit(args),
- // "get" => get::action_get(args),
- // "index" => index::action_index(args),
- // "list" => list::list_by_args(args),
- // "modify" => modify::do_modify(args),
- // "new" => new::do_new(args),
- // "select" => select::select_by_args(args),
- // "seq" => seq::action_seq(args),
- // "pretty" => prettyprint::prettyprint(),
- // "show" => show::do_show(args),
- // "undo" => undo::do_undo(args),
- // "unroll" => unroll::action_unroll(args),
- _ => {
- print_usage(cmd);
- Ok(())
- }
+fn main_internal(args: &ArgMatches, config: &Config) -> KhResult<()> {
+ match args.subcommand() {
+ ("agenda", Some(sub_args)) => {
+ let args = sub_args.values_of("args").map_or_else(|| Vec::new(), |x| x.collect::<Vec<&str>>());
+ agenda::show_events(&config, &args)
+ }
+ // "copy" => copy::do_copy(args),
+ // "cursor" => cursor::do_cursor(args),
+ // "delete" => delete::do_delete(args),
+ // "edit" => edit::do_edit(args),
+ // "get" => get::action_get(args),
+ ("index", Some(sub_args)) => index::action_index(sub_args),
+ // "list" => list::list_by_args(args),
+ // "modify" => modify::do_modify(args),
+ // "new" => new::do_new(args),
+ // "select" => select::select_by_args(args),
+ // "seq" => seq::action_seq(args),
+ // "pretty" => prettyprint::prettyprint(),
+ // "show" => show::do_show(args),
+ // "undo" => undo::do_undo(args),
+ // "unroll" => unroll::action_unroll(args),
+ _ => {
+ //print_usage(cmd);
+ Ok(())
}
}
}
@@ -107,7 +111,6 @@ fn init_logger(verbose: u64) {
// 2 => LevelFilter::Info,
// 3 => LevelFilter::Debug,
// _ => LevelFilter::Trace,
-
}
fn print_usage(name: &str) {