summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-02-25 14:00:28 +0100
committerNora <nora.widdecke@tu-bs.de>2019-02-25 14:00:28 +0100
commit8b93049bd70a8067ae7eff27edc48f683506995a (patch)
tree8cd29c18ab23a9336fb3a198a7b26f6d3ebf7999
parent7966395561ac1bdde89891963fc752313e5d65c7 (diff)
rename command argument structs for clarity
-rw-r--r--src/actions/cursor.rs14
-rw-r--r--src/actions/get.rs8
-rw-r--r--src/actions/index/action.rs4
-rw-r--r--src/actions/new.rs10
-rw-r--r--src/actions/unroll.rs4
-rw-r--r--src/cli.rs43
6 files changed, 41 insertions, 42 deletions
diff --git a/src/actions/cursor.rs b/src/actions/cursor.rs
index f881aef..6293a56 100644
--- a/src/actions/cursor.rs
+++ b/src/actions/cursor.rs
@@ -2,14 +2,14 @@ use crate::cursorfile;
use crate::utils::stdioutils;
use crate::KhResult;
use crate::seqfile;
-use crate::cli::{Cursor,Direction as CursorDirection};
+use crate::cli::{CursorArgs,Direction as CursorDirection};
enum Direction {
Up,
Down,
}
-pub fn do_cursor(args: &Cursor) -> KhResult<()> {
+pub fn do_cursor(args: &CursorArgs) -> KhResult<()> {
if !stdioutils::is_stdin_tty() {
write_stdin_to_cursorfile()?;
} else {
@@ -85,7 +85,7 @@ mod integration {
let expected_str = "hi there";
stdioutils::test_stdin_write(expected_str);
- let args = Cursor{direction: None};
+ let args = CursorArgs{direction: None};
do_cursor(&args).unwrap();
testdir.child(".khaleesi/cursor").assert(expected_str);
@@ -94,7 +94,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 = CursorArgs{direction: Some(CursorDirection::next)};
do_cursor(&args).unwrap();
let out = "1182988800 rfc_multi_day_allday.ics";
@@ -105,7 +105,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 = CursorArgs{direction: Some(CursorDirection::prev)};
do_cursor(&args).unwrap();
let out = "1544740200 twodaysacrossbuckets.ics\n";
@@ -119,7 +119,7 @@ mod integration {
let expected_str = "hi\nthere";
stdioutils::test_stdin_write(expected_str);
- let args = Cursor{direction: None};
+ let args = CursorArgs {direction: None};
let result = do_cursor(&args);
assert!(result.is_err());
@@ -130,7 +130,7 @@ mod integration {
fn test_no_stdin() {
let testdir = testutils::prepare_testdir("testdir_with_cursor");
- let args = Cursor{direction: None};
+ let args = CursorArgs {direction: None};
do_cursor(&args).unwrap();
let out = stdioutils::test_stdout_clear();
diff --git a/src/actions/get.rs b/src/actions/get.rs
index bba8a80..f755ee5 100644
--- a/src/actions/get.rs
+++ b/src/actions/get.rs
@@ -1,10 +1,10 @@
use crate::calendars;
use crate::KhResult;
-use crate::cli::{Get, GetArgs};
+use crate::cli::{GetArgs, GetQueryArgs};
-pub fn action_get(args: &Get) -> KhResult<()> {
+pub fn action_get(args: &GetArgs) -> KhResult<()> {
match args.query {
- GetArgs::calendars => action_get_calendars(),
+ GetQueryArgs::calendars => action_get_calendars(),
}
}
@@ -27,7 +27,7 @@ mod integration {
fn test_get_calendars() {
let _testdir = testutils::prepare_testdir("testdir_two_cals");
- let args = Get { query: GetArgs::calendars };
+ let args = GetArgs { query: GetQueryArgs::calendars };
action_get(&args).unwrap();
assert_eq!("first\nsecond\nsecond/second_sub\n", stdioutils::test_stdout_clear());
diff --git a/src/actions/index/action.rs b/src/actions/index/action.rs
index d4f855e..62cdf32 100644
--- a/src/actions/index/action.rs
+++ b/src/actions/index/action.rs
@@ -12,9 +12,9 @@ use crate::utils::fileutil;
use crate::utils::lock;
use crate::utils::misc;
use crate::KhResult;
-use crate::cli::Index;
+use crate::cli::IndexArgs;
-pub fn action_index(args: &Index) -> KhResult<()> {
+pub fn action_index(args: &IndexArgs) -> KhResult<()> {
let reindex = args.reindex;
let indexpath = match &args.path {
Some(path) => path.clone(),
diff --git a/src/actions/new.rs b/src/actions/new.rs
index e1c54f3..dac7931 100644
--- a/src/actions/new.rs
+++ b/src/actions/new.rs
@@ -2,7 +2,7 @@ use crate::defaults;
use crate::icalwrap::{IcalVCalendar,IcalTime,IcalTimeZone};
use crate::khline::KhLine;
use crate::utils::{misc,fileutil};
-use crate::cli::New;
+use crate::cli::NewArgs;
use crate::KhResult;
use crate::cursorfile;
@@ -17,7 +17,7 @@ struct EventProperties {
}
impl EventProperties {
- fn parse_from_args(args: &New) -> KhResult<EventProperties> {
+ fn parse_from_args(args: &NewArgs) -> KhResult<EventProperties> {
let calendar = EventProperties::parse_calendar(&args.calendar)?;
let from = EventProperties::parse_from(&args.from)?;
let to = EventProperties::parse_to(&args.to)?;
@@ -70,7 +70,7 @@ impl EventProperties {
}
}
-pub fn do_new(args: &New) -> KhResult<()> {
+pub fn do_new(args: &NewArgs) -> KhResult<()> {
let uid = misc::make_new_uid();
let ep = EventProperties::parse_from_args(args)?;
@@ -204,7 +204,7 @@ mod integration {
#[test]
fn test_parse_from_args() {
let _testdir = testutils::prepare_testdir("testdir_two_cals");
- let args = New { calendar: "second".to_string(),
+ let args = NewArgs { calendar: "second".to_string(),
from: "2017-11-03T12:30:00".to_string(),
to: "2017-11-07T11:11:00".to_string(),
summary: "summary text".to_string(),
@@ -258,7 +258,7 @@ mod integration {
testdata::setup();
let testdir = testutils::prepare_testdir("testdir_two_cals");
- let args = New { calendar: "second".to_string(),
+ let args = NewArgs { calendar: "second".to_string(),
from: "2017-11-03T12:30:00".to_string(),
to: "2017-11-07T11:11:00".to_string(),
summary: "summary text".to_string(),
diff --git a/src/actions/unroll.rs b/src/actions/unroll.rs
index 044eb59..882da7e 100644
--- a/src/actions/unroll.rs
+++ b/src/actions/unroll.rs
@@ -2,9 +2,9 @@ use std::path::Path;
use crate::khline::KhLine;
use crate::KhResult;
-use crate::cli::Unroll;
+use crate::cli::UnrollArgs;
-pub fn action_unroll(args: &Unroll) -> KhResult<()> {
+pub fn action_unroll(args: &UnrollArgs) -> KhResult<()> {
let filepath = &args.path;
do_unroll(filepath)?;
diff --git a/src/cli.rs b/src/cli.rs
index 5e49ed7..77e1177 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -20,13 +20,13 @@ pub struct CommandLine {
pub enum Command {
/// Show agenda view
#[structopt(name = "agenda", author = "")]
- Agenda(Agenda),
+ Agenda(AgendaArgs),
/// Copy event
#[structopt(name = "copy", author = "")]
Copy,
/// Interact with the cursor
#[structopt(name = "cursor", author = "")]
- Cursor(Cursor),
+ Cursor(CursorArgs),
/// Delete event
#[structopt(name = "delete", author = "")]
Delete,
@@ -35,19 +35,19 @@ pub enum Command {
Edit,
/// Get info about the calendar data
#[structopt(name = "get", author = "")]
- Get(Get),
+ Get(GetArgs),
/// Rebuild index
#[structopt(name = "index", author = "")]
- Index(Index),
+ Index(IndexArgs),
/// Select from the sequence
#[structopt(name = "list", author = "")]
- List(List),
+ List(ListArgs),
/// Create new event
#[structopt(name = "new", author = "")]
- New(New),
+ New(NewArgs),
/// Select from the index
#[structopt(name = "select", author = "")]
- Select(Select),
+ Select(SelectArgs),
/// Interact with the sequence
#[structopt(name = "seq", author = "")]
Seq,
@@ -59,19 +59,19 @@ pub enum Command {
Undo,
/// Unroll a recurring event
#[structopt(name = "unroll", author = "")]
- Unroll(Unroll),
+ Unroll(UnrollArgs),
}
#[derive(Debug, StructOpt)]
-pub struct Agenda {
- /// Show agenda view
+pub struct AgendaArgs {
+ /// Show agenda view
#[structopt(name = "args")]
pub args: Vec<String>,
}
#[derive(Debug, StructOpt)]
-pub struct Cursor {
- /// Move the cursor on the selection.
+pub struct CursorArgs {
+ /// Move the cursor on the selection.
#[structopt(name = "direction", raw(possible_values = "&Direction::variants()"))]
pub direction: Option<Direction>,
}
@@ -85,22 +85,21 @@ arg_enum! {
}
#[derive(Debug, StructOpt)]
-pub struct Get {
+pub struct GetArgs {
/// Show information about this
- #[structopt(name = "query", raw(possible_values = "&GetArgs::variants()"))]
- pub query: GetArgs,
+ #[structopt(name = "query", raw(possible_values = "&GetQueryArgs::variants()"))]
+ pub query: GetQueryArgs,
}
-
arg_enum! {
#[derive(Debug)]
- pub enum GetArgs{
+ pub enum GetQueryArgs{
calendars,
}
}
#[derive(Debug, StructOpt)]
-pub struct Index {
+pub struct IndexArgs {
/// Rebuild index
#[structopt(short = "r", long = "reindex")]
pub reindex: bool,
@@ -110,28 +109,28 @@ pub struct Index {
}
#[derive(Debug, StructOpt)]
-pub struct List {
+pub struct ListArgs {
/// the arguments for the selection
#[structopt(name = "args")]
pub args: Vec<String>,
}
#[derive(Debug, StructOpt)]
-pub struct Select {
+pub struct SelectArgs {
/// the arguments for the selection
#[structopt(name = "args")]
pub args: Vec<String>,
}
#[derive(Debug, StructOpt)]
-pub struct Unroll {
+pub struct UnrollArgs {
/// The file to unroll
#[structopt(name = "path", parse(from_os_str))]
pub path: PathBuf,
}
#[derive(Debug, StructOpt)]
-pub struct New {
+pub struct NewArgs {
/// the calendar
#[structopt(name = "calendar")]
pub calendar: String,