diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-02-24 23:14:36 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-02-24 23:19:22 +0100 |
commit | b54ac2e5e929deabaa1a992e98e826235dd33401 (patch) | |
tree | eb8907100bc64aae5d7b6cf6c766475f722abcbf | |
parent | 279ab83b5205ea5a758206c6713011d808dbddd8 (diff) |
cursor: show possible values in --help
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/actions/cursor.rs | 8 | ||||
-rw-r--r-- | src/cli.rs | 34 | ||||
-rw-r--r-- | src/lib.rs | 1 |
5 files changed, 25 insertions, 20 deletions
@@ -381,6 +381,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "indoc 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -25,6 +25,7 @@ lazy_static = "1.2.0" backtrace = "0.3" dirs = "1.0.4" structopt = "0.2.14" +clap = "2.32.0" [dev-dependencies] assert_fs = "0.11.3" diff --git a/src/actions/cursor.rs b/src/actions/cursor.rs index b009ab4..4ef951b 100644 --- a/src/actions/cursor.rs +++ b/src/actions/cursor.rs @@ -16,8 +16,8 @@ pub fn do_cursor(args: &Cursor) -> KhResult<()> { //println!("stdin is tty") if let Some(direction) = &args.direction { match direction { - CursorDirection::Prev => return cursor_sequence_move(&Direction::Up), - CursorDirection::Next => return cursor_sequence_move(&Direction::Down), + CursorDirection::prev => return cursor_sequence_move(&Direction::Up), + CursorDirection::next => return cursor_sequence_move(&Direction::Down), &_ => {} } }; @@ -95,7 +95,7 @@ mod integration { #[test] fn test_cursor_sequence_move_next() { let testdir = testutils::prepare_testdir("testdir_with_seq_and_cursor"); - let args = Cursor{direction: Some(CursorDirection::Next)}; + let args = Cursor{direction: Some(CursorDirection::next)}; do_cursor(&args).unwrap(); let out = "1182988800 rfc_multi_day_allday.ics"; @@ -106,7 +106,7 @@ mod integration { #[test] fn test_cursor_sequence_move_prev_at_end() { let testdir = testutils::prepare_testdir("testdir_with_seq_and_cursor"); - let args = Cursor{direction: Some(CursorDirection::Prev)}; + let args = Cursor{direction: Some(CursorDirection::prev)}; do_cursor(&args).unwrap(); let out = "1544740200 twodaysacrossbuckets.ics\n"; @@ -46,28 +46,30 @@ pub struct Agenda { #[derive(Debug, StructOpt)] pub struct Cursor { - /// Move the cursor on the selection. Uses "next" and "prev". - #[structopt(name = "direction")] + /// Move the cursor on the selection. + #[structopt(name = "direction", raw(possible_values = "&Direction::variants()"))] pub direction: Option<Direction>, } -#[derive(Debug, StructOpt)] -pub enum Direction { - Next, - Prev, -} - -impl std::str::FromStr for Direction{ - type Err = String; - fn from_str(s: &str) -> Result<Self, <Self as std::str::FromStr>::Err> { - match s { - "prev" => Ok(Direction::Prev), - "next" => Ok(Direction::Next), - &_ => Err("Expected 'prev' or 'next'".to_string()) - } +arg_enum! { +#[derive(Debug)] + pub enum Direction { + next, + prev, } } +//impl std::str::FromStr for Direction{ +// type Err = String; +// fn from_str(s: &str) -> Result<Self, <Self as std::str::FromStr>::Err> { +// match s { +// "prev" => Ok(Direction::Prev), +// "next" => Ok(Direction::Next), +// &_ => Err("Expected 'prev' or 'next'".to_string()) +// } +// } +//} + #[derive(Debug, StructOpt)] pub struct Index { /// Rebuild index @@ -29,3 +29,4 @@ use ical; #[macro_use] extern crate log; #[macro_use] extern crate indoc; #[macro_use] extern crate lazy_static; +#[macro_use] extern crate clap; |