From b54ac2e5e929deabaa1a992e98e826235dd33401 Mon Sep 17 00:00:00 2001 From: Nora Date: Sun, 24 Feb 2019 23:14:36 +0100 Subject: cursor: show possible values in --help --- Cargo.lock | 1 + Cargo.toml | 1 + src/actions/cursor.rs | 8 ++++---- src/cli.rs | 34 ++++++++++++++++++---------------- src/lib.rs | 1 + 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dea9f78..a40aa63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", diff --git a/Cargo.toml b/Cargo.toml index 1548fad..1278063 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"; diff --git a/src/cli.rs b/src/cli.rs index cc16d1c..948df5f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, } -#[derive(Debug, StructOpt)] -pub enum Direction { - Next, - Prev, -} - -impl std::str::FromStr for Direction{ - type Err = String; - fn from_str(s: &str) -> Result::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::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 diff --git a/src/lib.rs b/src/lib.rs index 65f78d1..0eeab59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; -- cgit v1.2.3