diff options
Diffstat (limited to 'src/bin/khaleesi.rs')
-rw-r--r-- | src/bin/khaleesi.rs | 111 |
1 files changed, 77 insertions, 34 deletions
diff --git a/src/bin/khaleesi.rs b/src/bin/khaleesi.rs index 6f0a2cc..26ac8ef 100644 --- a/src/bin/khaleesi.rs +++ b/src/bin/khaleesi.rs @@ -1,15 +1,51 @@ use log::error; -use khaleesi::config::Config; use khaleesi::actions::*; +use khaleesi::config::Config; use khaleesi::KhResult; use std::env; +#[macro_use] +extern crate structopt; + +use std::path::PathBuf; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +#[structopt(name = "khalessi", about = "Command line calendar tool.")] +struct Khaleesi { + /// Verbosity + #[structopt(short = "v", parse(from_occurrences))] + verbosity: u64, + #[structopt(subcommand)] + cmd: Index, +} + +#[derive(Debug, StructOpt)] +enum Index { + /// Rebuild index + #[structopt(name = "index")] + Index { + /// Rebuild index + #[structopt(short = "r", long = "reindex")] + reindex: bool, + }, +} + fn main() { + let matches = Khaleesi::clap().get_matches(); + println!("{:?}", matches); + + let opt = Khaleesi::from_args(); + println!("{:?}", opt); + stderrlog::new() .timestamp(stderrlog::Timestamp::Off) - .verbosity(3) + .verbosity({ + println!("Value for -v: {}", matches.occurrences_of("verbosity")); + 1 + matches.occurrences_of("verbosity") as usize + }) .init() .unwrap(); // 0 => LevelFilter::Error, @@ -18,27 +54,28 @@ fn main() { // 3 => LevelFilter::Debug, // _ => LevelFilter::Trace, - #[cfg(not(debug_assertions))] { + #[cfg(not(debug_assertions))] + { if let Some(dir) = dirs::home_dir() { use khaleesi::defaults; defaults::set_khaleesi_dir(&dir); } } - let args: Vec<String> = env::args().collect(); - let config = Config::read_config(); + //let args: Vec<String> = env::args().collect(); + //let config = Config::read_config(); - 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") { - let command = &binary_name[2..]; - args.push(command); - args.rotate_right(1); - } - let result = main_internal(binary_name, &args[..], &config); - if let Err(error) = result { - error!("{}", error) - } + //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") { + // let command = &binary_name[2..]; + // args.push(command); + // args.rotate_right(1); + //} + //let result = main_internal(binary_name, &args[..], &config); + //if let Err(error) = result { + // error!("{}", error) + //} } fn main_internal(binary_name: &str, args: &[&str], config: &Config) -> KhResult<()> { @@ -49,27 +86,33 @@ fn main_internal(binary_name: &str, args: &[&str], config: &Config) -> KhResult< 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(()) } + // "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 print_usage(name: &str) { - error!("Usage: {} index|select|list|agenda|copy|new|edit|show", name) + error!( + "Usage: {} index|select|list|agenda|copy|new|edit|show", + name + ) } |