diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-02-24 17:48:53 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-02-24 17:48:53 +0100 |
commit | f1553d27c111bfcc4fe1ce39788ccc7cbbefaa8d (patch) | |
tree | a72f956df24bc7bd94106ef1a5fabeb7ae30ed7a | |
parent | 0db742c95a0a74dd0699cdc0e52412a77ec3e103 (diff) |
make verbosity work
-rw-r--r-- | Cargo.lock | 38 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/bin/khaleesi.rs | 111 |
3 files changed, 116 insertions, 34 deletions
@@ -312,6 +312,14 @@ dependencies = [ ] [[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "humantime" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -387,6 +395,7 @@ dependencies = [ "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "stderrlog 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -797,6 +806,26 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "structopt" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "structopt-derive" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "syn" version = "0.15.26" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -901,6 +930,11 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "unicode-segmentation" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "unicode-width" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1042,6 +1076,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4743617a7464bbda3c8aec8558ff2f9429047e025771037df561d383337ff865" "checksum globwalk 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89fa2e29859da05acd066bd45996f05c271b271d7ec4a781f909682328f65d25" +"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ad03ca67dc12474ecd91fdb94d758cbd20cb4e7a78ebe831df26a9b7511e1162" "checksum indoc 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "730a9283f0eb1a0ee27817121aafc4395ca3dc33779ed2a5a314cbffbf787c19" @@ -1098,6 +1133,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum stderrlog 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "61dc66b7ae72b65636dbf36326f9638fb3ba27871bb737a62e2c309b87d91b70" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "670ad348dc73012fcf78c71f06f9d942232cdd4c859d4b6975e27836c3efc0c3" +"checksum structopt-derive 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ef98172b1a00b0bec738508d3726540edcbd186d50dfd326f2b1febbb3559f04" "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" @@ -1110,6 +1147,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unindent 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "834b4441326c660336850c5c0926cc20548e848967a5f57bc20c2b741c8d41f4" @@ -24,6 +24,7 @@ fs2 = "0.4.3" lazy_static = "1.2.0" backtrace = "0.3" dirs = "1.0.4" +structopt = "0.2.14" [dev-dependencies] assert_fs = "0.11.3" 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 + ) } |