diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-02-26 23:31:56 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-02-26 23:31:56 +0100 |
commit | b2d1176f6d6530804e6757ed20253ad8f375f30a (patch) | |
tree | 36ecb869cab572c9672259d1a68e9577f990130e /src | |
parent | 9e7cefd3dd5bff01ecbb063e3635a6a732593b64 (diff) |
move argument structs to the action modules
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/agenda.rs | 8 | ||||
-rw-r--r-- | src/actions/cursor.rs | 18 | ||||
-rw-r--r-- | src/actions/get.rs | 16 | ||||
-rw-r--r-- | src/actions/index/action.rs | 3 | ||||
-rw-r--r-- | src/actions/index/mod.rs | 13 | ||||
-rw-r--r-- | src/actions/list.rs | 8 | ||||
-rw-r--r-- | src/actions/modify.rs | 19 | ||||
-rw-r--r-- | src/actions/new.rs | 22 | ||||
-rw-r--r-- | src/actions/select.rs | 8 | ||||
-rw-r--r-- | src/actions/undo.rs | 2 | ||||
-rw-r--r-- | src/actions/unroll.rs | 11 | ||||
-rw-r--r-- | src/cli.rs | 113 |
12 files changed, 127 insertions, 114 deletions
diff --git a/src/actions/agenda.rs b/src/actions/agenda.rs index 6316d2d..22e27c2 100644 --- a/src/actions/agenda.rs +++ b/src/actions/agenda.rs @@ -1,6 +1,7 @@ use chrono::{DateTime, Datelike, TimeZone, Local, Date}; use yansi::{Style}; use itertools::Itertools; +use structopt::StructOpt; use crate::cursorfile; use crate::icalwrap::*; @@ -9,6 +10,13 @@ use crate::config::{Config,CalendarConfig}; use crate::khline::KhLine; use crate::KhResult; +#[derive(Debug, StructOpt)] +pub struct AgendaArgs { + /// Show agenda view + #[structopt(name = "args")] + pub args: Vec<String>, +} + pub fn show_events(config: &Config, args: &[&str]) -> KhResult<()> { let mut events = input::selection(args)?; diff --git a/src/actions/cursor.rs b/src/actions/cursor.rs index 6293a56..59fd418 100644 --- a/src/actions/cursor.rs +++ b/src/actions/cursor.rs @@ -2,7 +2,23 @@ use crate::cursorfile; use crate::utils::stdioutils; use crate::KhResult; use crate::seqfile; -use crate::cli::{CursorArgs,Direction as CursorDirection}; + +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +pub struct CursorArgs { + /// Move the cursor on the selection. + #[structopt(name = "direction", raw(possible_values = "&CursorDirection::variants()"))] + pub direction: Option<CursorDirection>, +} + +arg_enum! { +#[derive(Debug)] + pub enum CursorDirection { + next, + prev, + } +} enum Direction { Up, diff --git a/src/actions/get.rs b/src/actions/get.rs index f755ee5..2b3b21f 100644 --- a/src/actions/get.rs +++ b/src/actions/get.rs @@ -1,6 +1,20 @@ use crate::calendars; use crate::KhResult; -use crate::cli::{GetArgs, GetQueryArgs}; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +pub struct GetArgs { + /// Show information about this + #[structopt(name = "query", raw(possible_values = "&GetQueryArgs::variants()"))] + pub query: GetQueryArgs, +} + +arg_enum! { +#[derive(Debug)] + pub enum GetQueryArgs{ + calendars, + } +} pub fn action_get(args: &GetArgs) -> KhResult<()> { match args.query { diff --git a/src/actions/index/action.rs b/src/actions/index/action.rs index 01cf098..ffbe4f8 100644 --- a/src/actions/index/action.rs +++ b/src/actions/index/action.rs @@ -7,12 +7,11 @@ use std::time::SystemTime; use walkdir::DirEntry; use crate::defaults::*; -use super::indextime; +use super::{IndexArgs, indextime}; use crate::utils::fileutil; use crate::utils::lock; use crate::utils::misc; use crate::KhResult; -use crate::cli::IndexArgs; pub fn action_index(args: &IndexArgs) -> KhResult<()> { let reindex = args.reindex; diff --git a/src/actions/index/mod.rs b/src/actions/index/mod.rs index d7edc2c..cc4c0ae 100644 --- a/src/actions/index/mod.rs +++ b/src/actions/index/mod.rs @@ -3,3 +3,16 @@ mod indextime; mod bucketable; pub use self::action::action_index; + +use structopt::StructOpt; +use std::path::PathBuf; + +#[derive(Debug, StructOpt)] +pub struct IndexArgs { + /// Rebuild index + #[structopt(short = "r", long = "reindex")] + pub reindex: bool, + /// index path + #[structopt(name = "path", parse(from_os_str))] + pub path: Option<PathBuf>, +} diff --git a/src/actions/list.rs b/src/actions/list.rs index b7958b1..4c29188 100644 --- a/src/actions/list.rs +++ b/src/actions/list.rs @@ -1,6 +1,14 @@ use crate::selectors::SelectFilters; use crate::input; use crate::KhResult; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +pub struct ListArgs { + /// the arguments for the selection + #[structopt(name = "args")] + pub args: Vec<String>, +} pub fn list_by_args(args: &[&str]) -> KhResult<()> { let lines = input::default_input_khlines()?; diff --git a/src/actions/modify.rs b/src/actions/modify.rs index 113138a..1b58b2d 100644 --- a/src/actions/modify.rs +++ b/src/actions/modify.rs @@ -2,7 +2,24 @@ use crate::backup::backup; use crate::input; use crate::utils::fileutil::write_cal; use crate::KhResult; -use crate::cli::{ModifyCommand, ModifyArgs}; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +pub struct ModifyArgs { + /// Rebuild index + #[structopt(short = "n", long = "dry-run")] + pub dry_run: bool, + /// index path + #[structopt(subcommand)] + pub modify_cmd: ModifyCommand, +} + +#[derive(Debug, StructOpt)] +pub enum ModifyCommand { + /// Show agenda view + #[structopt(name = "remove-xlicerror", author = "")] + RemoveXlicerror, +} pub fn do_modify(args: &ModifyArgs) -> KhResult<()> { info!("do_modify"); diff --git a/src/actions/new.rs b/src/actions/new.rs index dac7931..e8c9cea 100644 --- a/src/actions/new.rs +++ b/src/actions/new.rs @@ -2,11 +2,29 @@ use crate::defaults; use crate::icalwrap::{IcalVCalendar,IcalTime,IcalTimeZone}; use crate::khline::KhLine; use crate::utils::{misc,fileutil}; -use crate::cli::NewArgs; - use crate::KhResult; use crate::cursorfile; use crate::calendars; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +pub struct NewArgs { + /// the calendar + #[structopt(name = "calendar")] + pub calendar: String, + /// from + #[structopt(name = "from")] + pub from: String, + /// to + #[structopt(name = "to")] + pub to: String, + /// summary + #[structopt(name = "summary")] + pub summary: String, + /// location + #[structopt(name = "location")] + pub location: String, +} struct EventProperties { calendar: String, diff --git a/src/actions/select.rs b/src/actions/select.rs index 67697a5..3ecda45 100644 --- a/src/actions/select.rs +++ b/src/actions/select.rs @@ -5,6 +5,14 @@ use crate::selectors::{SelectFilters,daterange::SelectFilterFrom,daterange::Sele use crate::utils::fileutil as utils; use crate::khline::KhLine; use crate::KhResult; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +pub struct SelectArgs { + /// the arguments for the selection + #[structopt(name = "args")] + pub args: Vec<String>, +} impl SelectFilters { fn predicate_path_skip_while(&self) -> impl Fn(&PathBuf) -> bool + '_ { diff --git a/src/actions/undo.rs b/src/actions/undo.rs index 2fa2c83..3e003a6 100644 --- a/src/actions/undo.rs +++ b/src/actions/undo.rs @@ -53,7 +53,7 @@ fn get_most_recent_backup() -> KhResult<PathBuf> { .filter_map(|result| result.ok()) .map(|dir_entry| dir_entry.path()) .max() - .ok_or("there are no backups, nothing to undo!".into()) + .ok_or_else(|| "there are no backups, nothing to undo!".into()) } fn ask_overwrite(path: &Path) -> bool { diff --git a/src/actions/unroll.rs b/src/actions/unroll.rs index 882da7e..7c1bece 100644 --- a/src/actions/unroll.rs +++ b/src/actions/unroll.rs @@ -1,8 +1,15 @@ -use std::path::Path; +use std::path::{PathBuf, Path}; +use structopt::StructOpt; use crate::khline::KhLine; use crate::KhResult; -use crate::cli::UnrollArgs; + +#[derive(Debug, StructOpt)] +pub struct UnrollArgs { + /// The file to unroll + #[structopt(name = "path", parse(from_os_str))] + pub path: PathBuf, +} pub fn action_unroll(args: &UnrollArgs) -> KhResult<()> { let filepath = &args.path; @@ -1,7 +1,15 @@ -use std::path::PathBuf; use structopt::StructOpt; use crate::actions::gen_completions::GenCompletionsArgs; +use crate::actions::agenda::AgendaArgs; +use crate::actions::cursor::CursorArgs; +use crate::actions::get::GetArgs; +use crate::actions::index::IndexArgs; +use crate::actions::list::ListArgs; +use crate::actions::modify::ModifyArgs; +use crate::actions::select::SelectArgs; +use crate::actions::unroll::UnrollArgs; +use crate::actions::new::NewArgs; #[derive(Debug, StructOpt)] #[structopt( @@ -69,106 +77,3 @@ pub enum Command { #[structopt(name = "unroll", author = "")] Unroll(UnrollArgs), } - -#[derive(Debug, StructOpt)] -pub struct AgendaArgs { - /// Show agenda view - #[structopt(name = "args")] - pub args: Vec<String>, -} - -#[derive(Debug, StructOpt)] -pub struct CursorArgs { - /// Move the cursor on the selection. - #[structopt(name = "direction", raw(possible_values = "&Direction::variants()"))] - pub direction: Option<Direction>, -} - -arg_enum! { -#[derive(Debug)] - pub enum Direction { - next, - prev, - } -} - -#[derive(Debug, StructOpt)] -pub struct GetArgs { - /// Show information about this - #[structopt(name = "query", raw(possible_values = "&GetQueryArgs::variants()"))] - pub query: GetQueryArgs, -} - -arg_enum! { -#[derive(Debug)] - pub enum GetQueryArgs{ - calendars, - } -} - -#[derive(Debug, StructOpt)] -pub struct IndexArgs { - /// Rebuild index - #[structopt(short = "r", long = "reindex")] - pub reindex: bool, - /// index path - #[structopt(name = "path", parse(from_os_str))] - pub path: Option<PathBuf>, -} - -#[derive(Debug, StructOpt)] -pub struct ListArgs { - /// the arguments for the selection - #[structopt(name = "args")] - pub args: Vec<String>, -} - -#[derive(Debug, StructOpt)] -pub struct ModifyArgs { - /// Rebuild index - #[structopt(short = "n", long = "dry-run")] - pub dry_run: bool, - /// index path - #[structopt(subcommand)] - pub modify_cmd: ModifyCommand, -} - -#[derive(Debug, StructOpt)] -pub enum ModifyCommand { - /// Show agenda view - #[structopt(name = "remove-xlicerror", author = "")] - RemoveXlicerror, -} - -#[derive(Debug, StructOpt)] -pub struct SelectArgs { - /// the arguments for the selection - #[structopt(name = "args")] - pub args: Vec<String>, -} - -#[derive(Debug, StructOpt)] -pub struct UnrollArgs { - /// The file to unroll - #[structopt(name = "path", parse(from_os_str))] - pub path: PathBuf, -} - -#[derive(Debug, StructOpt)] -pub struct NewArgs { - /// the calendar - #[structopt(name = "calendar")] - pub calendar: String, - /// from - #[structopt(name = "from")] - pub from: String, - /// to - #[structopt(name = "to")] - pub to: String, - /// summary - #[structopt(name = "summary")] - pub summary: String, - /// location - #[structopt(name = "location")] - pub location: String, -} |